// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

var MONTH_CODE = ["JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"];
var WEEK_CODE = ["MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"];

var orderReader = new Ext.data.JsonReader({
    totalProperty: 'totalProperty',
    root: 'root'
}, [{
    name: 'id'
}, {
    name: 'order_no'
}, {
    name: 'pnr'
}, {
    name: 'status'
}, {
    name: 'fly_date'
}, {
    name: 'fly_time'
}, {
    name: 'customer_id'
}, {
    name: 'customer',
    mapping: 'customer.name'
}, {
    name: 'creator_id'
}, {
    name: 'creator',
    mapping: 'creator.user_name'
}, {
    name: 'owner_id'
}, {
    name: 'link_man'
}, {
    name: 'link_tel'
}, {
    name: 'price_sum'
}, {
    name: 'sender_id'
}, {
    name: 'sender',
    mapping: 'sender.user_name'
}, {
    name: 'send_date'
}, {
    name: 'send_time'
}, {
    name: 'send_address'
}, {
    name: 'send_request'
}, {
    name: 'send_printed'
}, {
    name: 'jj_address'
}, {
    name: 'jj_request'
}, {
    name: 'jj_affirm_id'
}, {
    name: 'jj_affirmer',
    mapping: 'jj_affirmer.user_name'
}, {
    name: 'jj_affirm_date'
}, {
    name: 'jj_man_id'
}, {
    name: 'jj_man',
    mapping: 'jj_man.user_name'
}, {
    name: 'jj_time'
}, {
    name: 'receive_cash'
}, {
    name: 'pay_type'
}, {
    name: 'cash_checker_id'
}, {
    name: 'cash_checker',
    mapping: 'cash_checker.user_name'
}, {
    name: 'cash_get_date'
}, {
    name: 'remark'
}, {
    name: 'printer_id'
}, {
    name: 'printer',
    mapping: 'printer.user_name'
}, {
    name: 'affirm_date'
}, {
    name: 'canceler_id'
}, {
    name: 'canceler',
    mapping: 'canceler.user_name'
}, {
    name: 'cancel_date'
}, {
    name: 'cancel_reason'
}, {
    name: 'ticket_outer_id'
}, {
    name: 'ticket_outer',
    mapping: 'ticket_outer.user_name'
}, {
    name: 'ticket_out_date'
}, {
    name: 'tktl_date'
}, {
    name: 'tktl_time'
}, {
    name: 'insurance_number'
}, {
    name: 'insurance_outed'
}, {
    name: 'payment_type'
}, {
    name: 'last_editer_id'
}, {
    name: 'is_locked'
}, {
    name: 'order_request'
}, {
    name: 'activity'
}, {
    name: 'memo'
}, {
    name: 'seat'
}, {
    name: 'web'
}, {
    name: 'international'
}, {
    name: 'group'
}, {
    name: 'trx_id'
}, {
    name: 'trx_status'
}, {
    name: 'payment_platform_name'
}, {
    name: 'refund_amount'
}, {
    name: 'refund_remark'
}, {
    name: 'printer_date'
}, {
    name: 'updated_at'
}, {
    name: 'created_at'
}]);

var ticketReader = new Ext.data.JsonReader({
    totalProperty: 'totalProperty',
    root: 'root'
}, [{
    name: 'id'
}, {
    name: 'pnr'
}, {
    name: 'order_id'
}, {
    name: 'customer_id'
}, {
    name: 'passenger_id'
}, {
    name: 'passenger_name',
    mapping: 'passenger.name'
}, {
    name: 'card',
    mapping: 'passenger.card'
}, {
    name: 'ticket_no'
}, {
    name: 'air_no'
}, {
    name: 'fromto'
}, {
    name: 'fly_date'
}, {
    name: 'fly_time'
}, {
    name: 'arr_time'
}, {
    name: 'position'
}, {
    name: 'status_type'
}, {
    name: 'trip_type'
}, {
    name: 'ticket_type'
}, {
    name: 'price'
}, {
    name: 'status'
}, {
    name: 'airdrome_tax'
}, {
    name: 'fuel_tax'
}, {
    name: 'price_F'
}, {
    name: 'insurance_number'
}, {
    name: 'insurance_F'
}, {
    name: 'other'
}, {
    name: 'total_price'
}, {
    name: 'insurance_campany'
}, {
    name: 'insurance_outer_id'
}, {
    name: 'insurance_outer',
    mapping: 'insurance_outer.user_name'
}, {
    name: 'insurance_out_date'
}, {
    name: 'canceler_id'
}, {
    name: 'canceler',
    mapping: 'canceler.user_name'
}, {
    name: 'cancel_reason'
}, {
    name: 'point'
}, {
    name: 'rake_off'
}, {
    name: 'policy_id'
}, {
    name: 'father_id'
}]);

function formatMonthDay(str){
    if (str.length < 2) {
        str = "0" + str;
    }
    return str;
}

//取消订单
function cancelOrder(status, oid, no, dataStore, dataStore2){
    if (status == ORDER_STATUS_YQX) {
        Ext.MessageBox.alert('操作提示', '该订单已经取消');
    }
    else if (status == ORDER_STATUS_YTD) {
        Ext.MessageBox.alert('操作提示', '该订单已经退票');
    }
    else if (status == ORDER_STATUS_YZF) {
        Ext.MessageBox.alert('操作提示', '该订单已经作废');
    }
    else {
        var cancelReason = new Ext.form.TextArea({
            fieldLabel: '取消原因',
            name: 'reason',
            allowBlank: false,
            blankText: "取消原因不允许为空",
            height: 40,
            anchor: '90%'
        });
        var cancelOrderFormPanel = new Ext.form.FormPanel({
            //baseCls: 'x-plain',
            labelWidth: 60,
            labelAlign: 'right',
            frame: true,
            url: "/orders/del_pnr?id=" + oid,
            items: [cancelReason]
        });
        var cancelOrderWindow = new Ext.Window({
            title: '取消订单(' + no + ')',
            width: 260,
            height: 140,
            layout: 'fit',
            plain: true,
            bodyStyle: 'padding:5px;',
            buttonAlign: 'center',
            items: cancelOrderFormPanel,
            buttons: [{
                text: '确定',
                handler: function(){
                    if (cancelOrderFormPanel.form.isValid()) {
                        cancelOrderFormPanel.form.submit({
                            waitMsg: 'In processing',
                            success: function(form, action){
                                var info = "操作失败，具体失败原因请查询系统日志";
                                if (action.result && action.result.info && action.result.info != "") {
                                    info = action.result.info;
                                }
                                if (info.indexOf("成功") >= 0) {
                                    cancelOrderWindow.hide();
                                    Ext.MessageBox.alert('操作成功', info);
                                    dataStore.reload();
                                    if (dataStore2) {
                                        dataStore2.baseParams.id = "";
                                        dataStore2.reload();
                                    }
                                }
                                else {
                                    Ext.MessageBox.alert('操作失败', info);
                                    if (info.indexOf("已经被取消")>=0){
                                        dataStore.reload();
                                        if (dataStore2) {
                                            dataStore2.baseParams.id = "";
                                            dataStore2.reload();
                                        }
                                    }
                                }
                            },
                            failure: function(form, action){
                                var info = "操作失败，具体失败原因请查询系统日志";
                                if (action.result && action.result.info && action.result.info != "") {
                                    info = action.result.info;
                                }
                                Ext.MessageBox.alert('操作失败', info);
                                if (info.indexOf("已经被取消")>=0){
                                    dataStore.reload();
                                    if (dataStore2) {
                                        dataStore2.baseParams.id = "";
                                        dataStore2.reload();
                                    }
                                }
                            }
                        });
                    }
                }
            }, {
                text: '取消',
                handler: function(){
                    cancelOrderWindow.hide();
                }
            }]
        });
        cancelOrderWindow.show();
    }
}

//取消票
function cancelTicket(status, id, name, dataStore){
    if (status == TICKET_STATUS_YQX) {
        Ext.MessageBox.alert('操作提示', '这张票已经取消');
    }
    else if (status == TICKET_STATUS_YZF) {
        Ext.MessageBox.alert('操作提示', '这张票已经作废');
    }
    else if (status == TICKET_STATUS_YTP) {
        Ext.MessageBox.alert('操作提示', '这张票已经退票');
    }
    else if (status == TICKET_STATUS_YCP) {
        Ext.MessageBox.alert('操作提示', '这张票已经出票');
    }
    else {
        var cancelReason = new Ext.form.TextArea({
            fieldLabel: '取消原因',
            name: 'reason',
            allowBlank: false,
            blankText: "取消原因不允许为空",
            height: 40,
            anchor: '90%'
        });
        var cancelTicketFormPanel = new Ext.form.FormPanel({
            //baseCls: 'x-plain',
            labelWidth: 60,
            labelAlign: 'right',
            frame: true,
            url: "/orders/del_ticket?id=" + id,
            items: [cancelReason]
        });
        var cancelTicketWindow = new Ext.Window({
            title: '取消票(' + name + ')',
            width: 260,
            height: 140,
            layout: 'fit',
            plain: true,
            bodyStyle: 'padding:5px;',
            buttonAlign: 'center',
            items: cancelTicketFormPanel,
            buttons: [{
                text: '确定',
                handler: function(){
                    if (cancelTicketFormPanel.form.isValid()) {
                        cancelTicketFormPanel.form.submit({
                            waitMsg: 'In processing',
                            success: function(form, action){
                                var info = "操作失败，具体失败原因请查询系统日志";
                                if (action.result && action.result.info && action.result.info != "") {
                                    info = action.result.info;
                                }
                                if (info.indexOf("成功") >= 0) {
                                    cancelTicketWindow.hide();
                                    Ext.MessageBox.alert('操作成功', info);
                                    dataStore.reload();
                                }
                                else {
                                    Ext.MessageBox.alert('操作失败', info);
                                }
                            },
                            failure: function(form, action){
                                var info = "操作失败，具体失败原因请查询系统日志";
                                if (action.result && action.result.info && action.result.info != "") {
                                    info = action.result.info;
                                }
                                Ext.MessageBox.alert('操作失败', info);
                            }
                        });
                    }
                }
            }, {
                text: '取消',
                handler: function(){
                    cancelTicketWindow.hide();
                }
            }]
        });
        cancelTicketWindow.show();
    }
}

//修改订单
function ModOrder(dataStore, current_order_id, dataStore2){
    var status = new Ext.form.ComboBox({
        store: new Ext.data.Store({
            reader: new Ext.data.ArrayReader({}, ['value']),
            data: [['未确认'], ['确认出票'], ['立即出票']]
        }),
        name: 'status',
        fieldLabel: '出票状态',
        resiable: true,
        typeAhead: true,
        width: 90,
        handleHeight: 100,
        displayField: 'value',
        valueField: 'value',
        nameField: 'status',
        selectOnFocus: true,
        mode: 'local',
        selectOnFocus: true,
        triggerAction: 'all', //这个属性非常重要,可以在选择一个值以后,依然还显示其它的值.
        readOnly: true,
        emptyText: '',
        allowBlank: true,
        value: ''
    });
    
    var link_man = new Ext.form.TextField({
        fieldLabel: '联系人',
        name: 'link_man',
        allowBlank: true,
        blankText: "联系人不允许为空",
        anchor: '90%'
    });
    var link_tel = new Ext.form.TextField({
        fieldLabel: '联系人电话',
        name: 'link_tel',
        allowBlank: true,
        blankText: "联系电话不允许为空",
        anchor: '90%'
    });
    //送票地址关键字搜索
    var address_resultTpl = new Ext.XTemplate('<tpl for="."><div class="search-item">', '<h3>{address}</h3>', '</div></tpl>');
    var send_address = new Ext.form.ComboBox({
        store: new Ext.data.Store({
            proxy: new Ext.data.HttpProxy({
                url: '/customers/getAddressComboBox?orderid=' + current_order_id
            }),
            reader: new Ext.data.JsonReader({
                root: 'root'
            }, [{
                name: 'address'
            }])
        }),
        fieldLabel: '送票地址',
        name: 'send_address',
        allowBlank: true,
        //blankText: "送票地址不允许为空",
        anchor: '90%',
        //value: '',
        displayField: 'address',
        typeAhead: false,
        loadingText: 'Searching...',
        //width: 250,
        hideTrigger: false,
        tpl: address_resultTpl,
        //transform: 'send_address_el',
        //applyTo: 'send_address_el',
        minChars: 0,
        itemSelector: 'div.search-item',
        onSelect: function(record){
            //alert(record.data.address);
            send_address.setValue(record.data.address);
            if (this.isExpanded()) {
                this.collapse();
            }
        }
    });
    var sender = new Ext.form.ComboBox({
        store: new Ext.data.Store({
            proxy: new Ext.data.HttpProxy({
                url: '/users/getSendersComboBox'
            }),
            reader: new Ext.data.JsonReader({
                root: 'root'
            }, ['id', 'user_name'])
        }),
        fieldLabel: '送票人',
        name: 'sender',
        loadingText: '正在加载...',
        displayField: 'user_name',
        valueField: 'id',
        mode: 'remote',
        //hideTrigger: true,
        triggerAction: 'all',
        hiddenName: 'sender',//如果不想提交displayField，则在这儿指定以提交ID的值．
        //hiddenId:'sender',
        emptyText: '请选择...',
        editable: false,
        allowBlank: true,
        //forceSelection: false,
        width: 90,
        //maxHeight: 150,
        tabIndex: 4
    /*
         ,listeners: {
         select: function(combo, record, index){
         //cityCombo.clearValue();
         //cityCombo.store.loadData(record.data.city);
         }
         }
         */
    });
    var affirm_date = new Ext.form.DateField({
        fieldLabel: '确认日期',
        name: 'affirm_date',
        altFormats: 'Y-m-d',
        format: 'Y-m-d', //格式化日期
        //disabledDays: [0,6],	//不让选择周六，周日
        //disabledDaysText: "周末要休息",
        invalidText: "您输入的日期格式不对，正确格式为2008-01-01",
        allowBlank: true,
        //emptyText: '请选择...',
        inputType: '2008-01-01',
        //anchor: '50%'
        width: 90,
        minValue: today
    });
    var send_date = new Ext.form.DateField({
        fieldLabel: '送票日期',
        name: 'send_date',
        altFormats: 'Y-m-d',
        format: 'Y-m-d', //格式化日期
        //disabledDays: [0,6],	//不让选择周六，周日
        //disabledDaysText: "周末要休息",
        invalidText: "您输入的日期格式不对，正确格式为2008-01-01",
        allowBlank: true,
        //emptyText: '请选择...',
        inputType: '2008-01-01',
        //anchor: '50%'
        width: 90,
        minValue: today
    });
    var send_time = new Ext.form.TimeField({
        fieldLabel: '送票时间',
        name: 'send_time',
        altFormats: 'H:i',
        format: 'H:i',
        increment: 30,
        minValue: SEND_START_TIME,
        maxValue: SEND_END_TIME,
        //anchor: '50%'
        width: 90
    });
    var send_request = new Ext.form.TextField({
        fieldLabel: '送票要求',
        name: 'send_request',
        allowBlank: true,
        anchor: '90%'
    });
    var order_request = new Ext.form.TextField({
        fieldLabel: '客户要求',
        name: 'order_request',
        allowBlank: true,
        anchor: '90%'
    });
    var jj_address = new Ext.form.TextField({
        fieldLabel: '接机地址',
        name: 'jj_address',
        allowBlank: true,
        //emptyText: DEFAULT_JJ_ADDRESS,
        anchor: '90%'
    });
    var jj_time = new Ext.form.TimeField({
        fieldLabel: '接机时间',
        name: 'jj_time',
        altFormats: 'H:i',
        format: 'H:i',
        increment: 60,
        minValue: JJ_START_TIME,
        maxValue: JJ_END_TIME,
        //anchor: '50%'
        width: 80
    });
    var jj_request = new Ext.form.TextField({
        fieldLabel: '接机要求',
        name: 'jj_request',
        allowBlank: true,
        anchor: '90%'
    });
    
    var itemsArr = [status, affirm_date, order_request, {
        xtype: 'fieldset',
        checkboxToggle: true,
        //collapsible: true,
        checkboxName: 'checkbox_send',
        title: '送票',
        autoHeight: true,
        //defaults: {width: 210},
        defaultType: 'textfield',
        collapsed: false,
        items: [link_man, link_tel, send_address, send_date, send_time, sender, send_request]
    }, {
        xtype: 'fieldset',
        checkboxToggle: true,
        //collapsible: true,
        checkboxName: 'checkbox_jj',
        title: '接机',
        autoHeight: true,
        //defaults: {width: 210},
        defaultType: 'textfield',
        collapsed: false,
        items: [jj_address, jj_time, jj_request]
    }];
    
    var formPanel = new Ext.form.FormPanel({
        //baseCls: 'x-plain',
        labelWidth: 70,
        labelAlign: 'right',
        frame: true,
        //width: 390,
        url: "/orders/saveEditOrder?id=" + current_order_id,
        reader: new Ext.data.JsonReader({
            root: 'root'
        }, [{
            name: 'sender',
            mapping: 'sender.user_name'
        }, 'link_man', 'link_tel', 'send_address', 'send_date', 'send_time', 'send_request', 'order_request', 'jj_address', 'jj_time', 'jj_request', {
            name: 'affirm_date',
            type: 'date',
            dateFormat: 'Y/m/d'
        }]),
        items: itemsArr
    });
    
    formPanel.form.load({
        url: '/orders/getEditOrderInfoByID?id=' + current_order_id,
        waitMsg: '正在载入数据...',
        success: function(form, action){
        //Ext.MessageBox.alert('提示信息', '信息加载成功！');
        },
        failure: function(form, action){
            Ext.MessageBox.alert('提示信息', '信息加载失败');
        }
    });
    
    //窗口
    var modOrderWindow = new Ext.Window({
        title: '修改订单',
        width: 390,
        height: 520,
        layout: 'fit',
        plain: true,
        bodyStyle: 'padding:5px;',
        buttonAlign: 'center',
        items: formPanel,
        buttons: [{
            text: '保存',
            //disabled: true,
            handler: function(){
                // check form value
                if (formPanel.form.isValid()) {
                    formPanel.form.submit({
                        waitMsg: 'In processing',
                        success: function(form, action){
                            //alert(action.result.success);
                            //alert(action.response.responseText);
                            modOrderWindow.hide();
                            Ext.MessageBox.alert('操作信息', '修改订单成功');
                            dataStore.reload();
                            if (dataStore2) {
                                dataStore2.baseParams.id = current_order_id;
                                dataStore2.reload();
                            }
                        },
                        failure: function(form, action){
                            //alert(action.result.success);
                            //alert(action.response.responseText);
                            Ext.MessageBox.alert('操作信息', '修改订单失败');
                        }
                    });
                }
                else {
                    Ext.MessageBox.alert('错误消息', '请将必填项信息录入后再提交.');
                }
            }
        }, {
            text: '取消',
            handler: function(){
                modOrderWindow.hide();
            }
        }]
    });
    modOrderWindow.show();
}

//编辑票信息
function ModTicket(dataStore, id, dataStore2){
    var id_card = new Ext.form.TextField({
        fieldLabel: '证件号码',
        name: 'id_card',
        allowBlank: true,
        anchor: '90%'
    });
    var price = new Ext.form.NumberField({
        fieldLabel: '机票价格',
        name: 'price',
        allowBlank: false,
        blankText: "机票价格不允许为空",
        anchor: '90%'
    });
    var price_F = new Ext.form.NumberField({
        fieldLabel: '机票F',
        name: 'price_F',
        allowBlank: true,
        anchor: '90%'
    });
    var fuel_tax = new Ext.form.NumberField({
        fieldLabel: '附加费',
        name: 'fuel_tax',
        allowBlank: false,
        blankText: "附加费不允许为空",
        anchor: '90%'
    });
    var airdrome_tax = new Ext.form.NumberField({
        fieldLabel: '机场费税',
        name: 'airdrome_tax',
        allowBlank: false,
        blankText: "机场费税不允许为空",
        anchor: '90%'
    });
    var insurance_number = new Ext.form.NumberField({
        fieldLabel: '保险份数',
        name: 'insurance_number',
        allowBlank: false,
        blankText: "保险份数不允许为空",
        anchor: '90%'
    //,emptyText: '0'
    });
    var insurance_F = new Ext.form.NumberField({
        fieldLabel: '保险F',
        name: 'insurance_F',
        allowBlank: true,
        anchor: '90%'
    });
    var other = new Ext.form.NumberField({
        fieldLabel: '其他',
        name: 'other',
        allowBlank: true,
        anchor: '90%'
    });
    var point = new Ext.form.NumberField({
        fieldLabel: '积分',
        name: 'point',
        allowBlank: true,
        anchor: '90%'
    });
    
    var formPanel = new Ext.form.FormPanel({
        //baseCls: 'x-plain',
        labelWidth: 60,
        labelAlign: 'right',
        frame: true,
        url: "/orders/saveEditTicket?id=" + id,
        reader: new Ext.data.JsonReader({
            root: 'root'
        }, ['price', 'price_F', 'fuel_tax', 'airdrome_tax', 'insurance_number', 'insurance_F', 'other', {
            name: 'id_card',
            mapping: 'passenger.card'
        }, 'point']),
        items: [id_card, price, price_F, fuel_tax, airdrome_tax, insurance_number, insurance_F, other, point]
    });
    
    formPanel.form.load({
        url: '/orders/getEditTicketInfoByID?id=' + id,
        waitMsg: '正在载入数据...',
        success: function(form, action){
        //Ext.MessageBox.alert('提示信息', '信息加载成功！');
        },
        failure: function(form, action){
            Ext.MessageBox.alert('提示信息', '信息加载失败');
        }
    });
    
    var fixWindow = new Ext.Window({
        title: '编辑修改',
        width: 260,
        height: 330,
        layout: 'fit',
        plain: true,
        bodyStyle: 'padding:5px;',
        buttonAlign: 'center',
        items: formPanel,
        buttons: [{
            text: '保存',
            handler: function(){
                // check form value
                if (formPanel.form.isValid()) {
                    formPanel.form.submit({
                        waitMsg: 'In processing',
                        success: function(form, action){
                            var info = "操作失败，具体失败原因请查询系统日志";
                            if (action.result && action.result.info && action.result.info != "") {
                                info = action.result.info;
                            }
                            if (info.indexOf("成功") >= 0) {
                                Ext.MessageBox.alert('编辑成功', info);
                                fixWindow.hide();
                                dataStore.reload();
                                if (dataStore2) {
                                    dataStore2.reload();
                                }
                            }else{
                                Ext.MessageBox.alert('编辑失败', info);
                            }
                        },
                        failure: function(form, action){
                            Ext.MessageBox.alert('操作信息', '操作失败');
                        }
                    });
                }
                else {
                    Ext.MessageBox.alert('错误消息', '请将必填项信息录入后再提交.');
                }
            }
        }, {
            text: '取消',
            handler: function(){
                fixWindow.hide();
            }
        }]
    });
    fixWindow.show();
}

//婴儿票
function addChild(dataStore, id){

    var baby_name = new Ext.form.TextField({
        fieldLabel: '婴儿姓名',
        name: 'baby_name',
        allowBlank: false,
        blankText: "婴儿姓名不允许为空",
        anchor: '90%'
    });
    var baby_date = new Ext.form.DateField({
        fieldLabel: '出生日期',
        name: 'baby_date',
        altFormats: 'Y-m-d',
        format: 'Y-m-d', //格式化日期
        //disabledDays: [0,6],	//不让选择周六，周日
        //disabledDaysText: "周末要休息",
        invalidText: "您输入的日期格式不对，正确格式为2008-01-01",
        allowBlank: false,
        blankText: "婴儿出生日期必须选择",
        //emptyText: '请选择...',
        inputType: '2008-01-01',
        //anchor: '50%'
        width: 100
    });
    var insurance_number = new Ext.form.NumberField({
        fieldLabel: '保险份数',
        name: 'insurance_number',
        allowBlank: false,
        blankText: "保险份数不允许为空",
        anchor: '90%',
        value: 0
    //emptyText: '0'
    });
    
    var formPanel = new Ext.form.FormPanel({
        //baseCls: 'x-plain',
        labelWidth: 60,
        labelAlign: 'right',
        frame: true,
        url: "/orders/addChildTicket?id=" + id,
        items: [baby_name, baby_date, insurance_number]
    });
    
    var fixWindow = new Ext.Window({
        title: '婴儿票',
        width: 260,
        height: 180,
        layout: 'fit',
        plain: true,
        bodyStyle: 'padding:5px;',
        buttonAlign: 'center',
        items: formPanel,
        buttons: [{
            text: '提交',
            handler: function(){
                if (formPanel.form.isValid()) {
                    formPanel.form.submit({
                        waitMsg: 'In processing',
                        success: function(form, action){
                            var info = "操作失败，具体失败原因请查询系统日志";
                            if (action.result && action.result.info && action.result.info != "") {
                                info = action.result.info;
                            }
                            Ext.MessageBox.alert('操作信息', info);
                            if (info.indexOf("成功") >= 0) {
                                fixWindow.hide();
                                dataStore.reload();
                            }
                        },
                        failure: function(form, action){
                            var info = "操作失败，具体失败原因请查询系统日志";
                            if (action.result && action.result.info && action.result.info != "") {
                                info = action.result.info;
                            }
                            Ext.MessageBox.alert('操作信息', info);
                        }
                    });
                }
            }
        }, {
            text: '取消',
            handler: function(){
                fixWindow.hide();
            }
        }]
    });
    fixWindow.show();
}

//取消接机
function cancelJJ(id, dataStore, dataStore2){
    Ext.Ajax.request({
        url: '/orders/cancelJJ',
        params: 'id=' + id,
        method: 'POST',
        success: function(result, request){
            if (result.responseText.indexOf("成功") >= 0) {
                Ext.MessageBox.alert('操作成功', "取消成功");
                dataStore.reload();
                if (dataStore2) {
                    dataStore2.baseParams.id = "";
                    dataStore2.reload();
                }
            }
            else {
                Ext.MessageBox.alert('操作失败', result.responseText);
            }
        },
        failure: function(result, request){
            Ext.MessageBox.alert('操作失败', '取消失败');
        }
    });
}

//发短信
function sendSMS(phone_number){
    var phoneNumber = new Ext.form.TextField({
        fieldLabel: '电话',
        name: 'phone_number',
        allowBlank: false,
        blankText: "电话不允许为空",
        anchor: '90%'
    });
    
    var content = new Ext.form.TextArea({
        fieldLabel: '内容',
        name: 'content',
        allowBlank: false,
        //hideLabel: true,
        height: 150,
        blankText: "短信内容不允许为空",
        anchor: '90%'
    });
    
    var smsform = new Ext.form.FormPanel({
        baseCls: 'x-plain',
        labelWidth: 35,
        url: '/index/sendSMS',
        defaultType: 'textfield',
        labelAlign: 'right',
        items: [phoneNumber, content]
    });
    
    phoneNumber.setValue(phone_number);
    var window = new Ext.Window({
        title: '短信发送（字数不得超过60字）',
        width: 400,
        height: 270,
        minWidth: 300,
        minHeight: 270,
        layout: 'fit',
        plain: true,
        bodyStyle: 'padding:5px;',
        buttonAlign: 'center',
        items: smsform,
        buttons: [{
            text: '发送',
            handler: function(){
                // check form value
                Ext.Ajax.request({
                    url: '/index/sendSMS',
                    params: smsform.form.getValues(true),
                    method: 'POST',
                    success: function(result, request){
                        if (result.responseText == "SUCCESS") {
                            Ext.MessageBox.alert('提示', "短消息发送成功!");
                        }
                        else {
                            Ext.MessageBox.alert('提示', result.responseText);
                        }
                    },
                    failure: function(result, request){
                        Ext.MessageBox.alert('错误提示', '网络故障发送失败!');
                    }
                });
            }
        }, {
            text: '取消',
            handler: function(){
                window.destroy();
            }
        }]
    });
    
    window.show();
}

//退票
function drawTicket(dataStore, current_ticket_id, dataStore2){
    var draw_name = new Ext.form.TextField({
        fieldLabel: '旅客姓名',
        name: 'd_name',
        readOnly: true,
        anchor: '90%'
    });
    var draw_price = new Ext.form.TextField({
        fieldLabel: '票价',
        name: 'd_price',
        readOnly: true,
        anchor: '90%'
    });
    var draw_tax = new Ext.form.TextField({
        fieldLabel: '机建费税',
        name: 'd_tax',
        readOnly: true,
        anchor: '90%'
    });
    var draw_fuel = new Ext.form.TextField({
        fieldLabel: '燃油附加',
        name: 'd_fuel',
        readOnly: true,
        anchor: '90%'
    });
    var draw_f = new Ext.form.TextField({
        fieldLabel: 'F',
        name: 'd_f',
        readOnly: true,
        anchor: '90%'
    });
    var draw_other = new Ext.form.TextField({
        fieldLabel: '其他',
        name: 'd_other',
        readOnly: true,
        anchor: '90%'
    });
    var draw_total = new Ext.form.TextField({
        fieldLabel: '总计',
        name: 'd_total',
        readOnly: true,
        anchor: '90%'
    });
    var draw_money = new Ext.form.TextField({
        fieldLabel: '退票费',
        name: 'd_money',
        allowBlank: false,
        blankText: "退票费不允许为空",
        anchor: '90%'
    });
    var draw_remark = new Ext.form.TextField({
        fieldLabel: '备注',
        name: 'd_remark',
        allowBlank: false,
        height: 60,
        anchor: '90%'
    });
    var draw_insurance = new Ext.form.TextField({
        fieldLabel: '保险份数',
        name: 'd_insurance',
        readOnly: true,
        anchor: '90%'
    });
    //航班列表
    var drawDS = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
            url: '/orders/getTicketsByTicketId?tid='+current_ticket_id
        }),
        reader: new Ext.data.JsonReader({
            root: 'root'
        }, [{
            name: 'air_no'
        }, {
            name: 'fromto'
        }, {
            name: 'position'
        }, {
            name: 'price'
        }, {
            name: 'fly_date'
        }, {
            name: 'fly_time'
        }, {
            name: 'plane_type'
        }, {
            name: 'airdrome_tax'
        }, {
            name: 'fuel_tax'
        }, {
            name: 'price_F'
        }, {
            name: 'other'
        }, {
            name: 'insurance_number'
        }])
    });
    var drawCM = new Ext.grid.ColumnModel([{
        header: "航班号",
        width: 60,
        sortable: true,
        dataIndex: 'air_no'
    }, {
        header: "航程",
        width: 60,
        sortable: true,
        dataIndex: 'fromto',
        hidden: true
    }, {
        header: "舱位",
        width: 50,
        sortable: true,
        dataIndex: 'position'
    }, {
        header: "价格",
        width: 50,
        sortable: true,
        dataIndex: 'price'
    }, {
        header: "乘机日期",
        width: 70,
        sortable: true,
        dataIndex: 'fly_date'
    }, {
        header: "起飞时间",
        width: 60,
        sortable: true,
        dataIndex: 'fly_time'
    }, {
        header: "机型",
        width: 40,
        sortable: true,
        dataIndex: 'plane_type'
    }, {
        header: "机建",
        width: 40,
        sortable: true,
        dataIndex: 'airdrome_tax'
    }, {
        header: "燃油",
        width: 40,
        sortable: true,
        dataIndex: 'fuel_tax'
    }, {
        header: "F",
        width: 30,
        sortable: true,
        dataIndex: 'price_F'
    }, {
        header: "其他",
        width: 40,
        sortable: true,
        dataIndex: 'other'
    }, {
        header: "保险",
        width: 40,
        sortable: true,
        dataIndex: 'insurance_number'
    }]);
    var drawGrid = new Ext.grid.GridPanel({
        loadMask: true,
        autoWidth: true,
        collapsible: true,
        animCollapse: false,
        ds: drawDS,
        cm: drawCM,
        height: 130
    });

    var formPanel = new Ext.form.FormPanel({
        //baseCls: 'x-plain',
        labelWidth: 55,
        labelAlign: 'right',
        frame: true,
        //width: 390,
        url: "/orders/saveDrawTicket?tid=" + current_ticket_id,
        reader: new Ext.data.JsonReader({
            root: 'root'
        }, [{
            name: 'd_name'
        }, {
            name: 'd_price'
        }, {
            name: 'd_tax'
        }, {
            name: 'd_fuel'
        }, {
            name: 'd_f'
        }, {
            name: 'd_other'
        }, {
            name: 'd_total'
        }, {
            name: 'd_insurance'
        }]
        ),
        items: [drawGrid,
        {
            layout: 'column',
            items: [{
                columnWidth: .5,
                layout: 'form',
                items: draw_name
            }, {
                columnWidth: .5,
                layout: 'form',
                items: draw_price
            }]
        }, {
            layout: 'column',
            items: [{
                columnWidth: .5,
                layout: 'form',
                items: draw_tax
            }, {
                columnWidth: .5,
                layout: 'form',
                items: draw_fuel
            }]
        }, {
            layout: 'column',
            items: [{
                columnWidth: .5,
                layout: 'form',
                items: draw_f
            }, {
                columnWidth: .5,
                layout: 'form',
                items: draw_other
            }]

        }, {
            layout: 'column',
            items: [{
                columnWidth: .5,
                layout: 'form',
                items: draw_total
            }, {
                columnWidth: .5,
                layout: 'form',
                items: draw_insurance
            }]

        }, draw_money, draw_remark]
    });
    drawDS.load();
        
    formPanel.form.load({
        url: '/orders/getDrawTicketsInfo?tid=' + current_ticket_id,
        waitMsg: '正在载入数据...',
        success: function(form, action){
        //Ext.MessageBox.alert('提示信息', '信息加载成功！');
        },
        failure: function(form, action){
            Ext.MessageBox.alert('提示信息', '信息加载失败');
        }
    });

    var drawWindow = new Ext.Window({
        title: '办理退票',
        width: 560,
        height: 430,
        layout: 'fit',
        plain: true,
        bodyStyle: 'padding:5px;',
        buttonAlign: 'center',
        items: formPanel,
        buttons: [{
            text: '确认退票',
            handler: function(){
                if (formPanel.form.isValid()) {
                    var money = parseInt(draw_money.getValue());
                    var insur = parseInt(draw_insurance.getValue()) * 20;
                    var total = parseInt(draw_total.getValue());
                    var tui = total - insur - money;
                    //alert(total + "--" + insur + "--" + money + "--" + tui);
                    Ext.MessageBox.confirm('确认操作', '<center>应该退<font color=red>' + tui + '.00</font>元.<br>确定要进行退票操作?</center>', submitDrawT);
                }
                else {
                    Ext.MessageBox.alert('错误消息', '请将必填项信息录入后再提交.');
                }
            }
        }, {
            text: '取消',
            handler: function(){
                drawWindow.hide();
            }
        }]
    });
    drawWindow.show();

    submitDrawT = function(btn){
        if (btn == 'yes') {
            formPanel.form.submit({
                waitMsg: 'In processing',
                success: function(form, action){
                    var info = "操作失败，具体失败原因请查询系统日志";
                    if (action.result && action.result.info && action.result.info != "") {
                        info = action.result.info;
                    }
                    Ext.MessageBox.alert('操作信息', info);
                    if (info.indexOf("成功") >= 0) {
                        drawWindow.hide();
                        dataStore.reload();
                        if (dataStore2) {
                            dataStore2.reload();
                        }
                    }
                },
                failure: function(form, action){
                    var info = "操作失败，具体失败原因请查询系统日志";
                    if (action.result && action.result.info && action.result.info != "") {
                        info = action.result.info;
                    }
                    Ext.MessageBox.alert('操作信息', info);
                }
            });
        }
    }
}
  
//分离 pnr
function saPnrFunction(id,dataStore,dataStore2){
    var idStr = new Ext.form.Hidden({
        name: 'id_str'
    });
    var nameStr = new Ext.form.Hidden({
        name: 'name_str'
    });
    var saSM = new Ext.grid.CheckboxSelectionModel();
    var saCM = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), saSM, {
        header: '编号',
        dataIndex: 'id',
        hidden: true
    }, {
        header: '姓名',
        dataIndex: 'pass_name',
        width: 70
    }]);
    var saDS = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
            url: '/orders/getPassengerNamesById?id='+id
        }),
        reader: new Ext.data.JsonReader({
            root: 'root'
        }, [{
            name: 'id'
        }, {
            name: 'pass_name'
        }])
    });
    var saPnrGrid = new Ext.grid.GridPanel({
        loadMask: true,
        autoWidth: true,
        collapsible: true,
        animCollapse: false,
        ds: saDS,
        cm: saCM,
        sm: saSM,
        height: 130
    });
    var formPanel = new Ext.form.FormPanel({
        //baseCls: 'x-plain',
        labelWidth: 55,
        labelAlign: 'right',
        frame: true,
        url: "/orders/saPnr?id=" + id,
        items: [saPnrGrid,idStr,nameStr]
    });
    saDS.load();
    var saPnrWindow = new Ext.Window({
        title: '分离PNR',
        width: 250,
        height: 200,
        //minWidth: 300,
        //minHeight: 300,
        layout: 'fit',
        plain: true,
        bodyStyle: 'padding:5px;',
        buttonAlign: 'center',
        items: formPanel,
        modal: true,
        buttons: [{
            text: '提交',
            handler: function(){
                if (formPanel.form.isValid()) {
                    var ids = "";
                    var names = "";
                    var records = saPnrGrid.getSelectionModel().getSelections();
                    if (records.length==saPnrGrid.getStore().reader.jsonData.root.length){
                        Ext.MessageBox.alert('提示', '不能选择全部乘客');
                    }else{
                        for (i = 0; i < records.length; i++) {
                            if (ids!=""){
                                ids += ",";
                            }
                            ids += records[i].data['id'];
                            if (names!=""){
                                names += ",";
                            }
                            names += records[i].data['pass_name'];
                        }
                        alert(ids+"=="+names);
                        idStr.setValue(ids);
                        nameStr.setValue(nameStr);
                        formPanel.form.submit({
                            waitMsg: 'In processing',
                            success: function(form, action){
                                var info = "";
                                if (action && action.result) {
                                    info = action.result.info;
                                }
                                else {
                                    info = '提交失败,具体失败原因请查询日志文件';
                                }
                                if (info.indexOf("成功")>=0){
                                    Ext.MessageBox.alert('操作成功', info);
                                    saPnrWindow.destroy();
                                    dataStore.reload();
                                    if (dataStore2){
                                        dataStore2.baseParams.id = id;
                                        dataStore2.reload();
                                    }
                                }else{
                                    Ext.MessageBox.alert('操作失败', info);
                                }
                            },
                            failure: function(form, action){
                                Ext.MessageBox.alert('操作失败', '提交失败');
                            }
                        });
                    }
                }

            }
        }, {
            text: '取消',
            handler: function(){
                saPnrWindow.destroy();
            }
        }]
    });
    saPnrWindow.show();
}
    
//订单转换客户
function changeCustomer(dataStore, current_order_id, dataStore2){

    var customer = new Ext.form.ComboBox({
        store: new Ext.data.Store({
            proxy: new Ext.data.HttpProxy({
                url: '/customers/getAllCustomerComboBox'
            }),
            reader: new Ext.data.JsonReader({
                root: 'root'
            }, ['id', 'name'])
        }),
        fieldLabel: '客户',
        name: 'customer',
        loadingText: '正在加载...',
        displayField: 'name',
        valueField: 'id',
        mode: 'remote',
        //hideTrigger: true,
        triggerAction: 'all',
        hiddenName: 'customer',//如果不想提交displayField，则在这儿指定以提交ID的值．
        //hiddenId:'customer',
        emptyText: '请选择...',
        editable: false,
        allowBlank: false,
        //forceSelection: false,
        width: 100,
        //maxHeight: 150,
        tabIndex: 4
    /*
         ,listeners: {
         select: function(combo, record, index){
         //cityCombo.clearValue();
         //cityCombo.store.loadData(record.data.city);
         }
         }
         */
    });
    
    var formPanel = new Ext.form.FormPanel({
        //baseCls: 'x-plain',
        labelWidth: 45,
        labelAlign: 'right',
        frame: true,
        //width: 390,
        url: "/orders/saveEditOrder?id=" + current_order_id + "&onlyCustomer=yes",
        reader: new Ext.data.JsonReader({
            root: 'root'
        }, [{
            name: 'customer',
            mapping: 'customer.name'
        }]),
        items: customer
    });
    
    formPanel.form.load({
        url: '/orders/getEditOrderInfoByID?id=' + current_order_id,
        waitMsg: '正在载入数据...',
        success: function(form, action){
        //Ext.MessageBox.alert('提示信息', '信息加载成功！');
        },
        failure: function(form, action){
            Ext.MessageBox.alert('提示信息', '信息加载失败');
        }
    });
    
    var fixWindow = new Ext.Window({
        title: '订单转换',
        width: 260,
        height: 130,
        layout: 'fit',
        plain: true,
        bodyStyle: 'padding:5px;',
        buttonAlign: 'center',
        items: formPanel,
        buttons: [{
            text: '保存',
            handler: function(){
                // check form value
                if (formPanel.form.isValid()) {
                    formPanel.form.submit({
                        waitMsg: 'In processing',
                        success: function(form, action){
                            var info = "操作失败，具体失败原因请查询系统日志";
                            if (action.result && action.result.info && action.result.info != "") {
                                info = action.result.info;
                            }
                            Ext.MessageBox.alert('操作信息', info);
                            if (info.indexOf("成功") >= 0) {
                                fixWindow.hide();
                                dataStore.reload();
                                if (dataStore2) {
                                    dataStore2.reload();
                                }
                            }
                        },
                        failure: function(form, action){
                            var info = "操作失败，具体失败原因请查询系统日志";
                            if (action.result && action.result.info && action.result.info != "") {
                                info = action.result.info;
                            }
                            Ext.MessageBox.alert('操作信息', info);
                        }
                    });
                }
                else {
                    Ext.MessageBox.alert('错误消息', '请将必填项信息录入后再提交.');
                }
            }
        }, {
            text: '取消',
            handler: function(){
                fixWindow.hide();
            }
        }]
    });
    fixWindow.show();
}

//显示客户信息
function showCustomerInfo(id){

    var customerName = new Ext.form.TextField({
        fieldLabel: '客户名称',
        allowBlank: true,
        name: 'name',
        anchor: '90%'
    });
    var birthDay = new Ext.form.TextField({
        fieldLabel: '生日',
        allowBlank: true,
        name: 'birthday',
        width: '90'
    });
    var customerType = new Ext.form.TextField({
        fieldLabel: '客户类型',
        allowBlank: true,
        name: 'customer_type',
        anchor: '90%'
    });
    var cardType = new Ext.form.TextField({
        fieldLabel: '证件类型',
        allowBlank: true,
        name: 'card_type',
        anchor: '90%'
    });
    var sex = new Ext.form.TextField({
        fieldLabel: '性别',
        allowBlank: true,
        name: 'sex',
        width: '40'
    });
    var customerAddress = new Ext.form.TextField({
        fieldLabel: '地址',
        allowBlank: true,
        name: 'address',
        anchor: '90%'
    });
    var card = new Ext.form.TextField({
        fieldLabel: '证件号码',
        allowBlank: true,
        name: 'card',
        anchor: '90%'
    });
    var phone = new Ext.form.TextField({
        fieldLabel: '电话',
        allowBlank: true,
        name: 'phone',
        //anchor: '90%'
        width: 100
    });
    var linkman = new Ext.form.TextField({
        fieldLabel: '联系人',
        allowBlank: true,
        name: 'linkman',
        anchor: '90%'
    });
    var linkmanPhone = new Ext.form.TextField({
        fieldLabel: '联系人电话',
        allowBlank: true,
        name: 'linkman_phone',
        anchor: '90%'
    });
    // create form panel
    var editFormPanel = new Ext.form.FormPanel({
        //baseCls: 'x-plain',
        frame: true,
        labelWidth: 75,
        labelAlign: 'right',
        reader: new Ext.data.JsonReader({
            root: 'root'
        }, [{
            name: 'id'
        }, {
            name: 'name'
        }, {
            name: 'sex'
        }, {
            name: 'phone'
        }, {
            name: 'customer_type'
        }, {
            name: 'address'
        }, {
            name: 'card_type'
        }, {
            name: 'card'
        }, {
            name: 'linkman'
        }, {
            name: 'linkman_phone'
        }, {
            name: 'birthday'
        /*
             }, {
             name: 'birthday',
             type: 'date',
             dateFormat: 'Y/m/d'
                 */
        }]),
        items: [customerName, {
            layout: 'column',
            border: false,
            items: [{
                columnWidth: .4,
                layout: 'form',
                border: false,
                items: [sex]
            }, {
                columnWidth: .6,
                layout: 'form',
                border: false,
                items: [customerType]
            }]
        }, {
            layout: 'column',
            border: false,
            items: [{
                columnWidth: .4,
                layout: 'form',
                border: false,
                items: [phone]
            }, {
                columnWidth: .6,
                layout: 'form',
                border: false,
                items: [birthDay]
            }]
        }, customerAddress, {
            layout: 'column',
            border: false,
            items: [{
                columnWidth: .4,
                layout: 'form',
                border: false,
                items: [cardType]
            }, {
                columnWidth: .6,
                layout: 'form',
                border: false,
                items: [card]
            }]
        }, {
            layout: 'column',
            border: false,
            items: [{
                columnWidth: .4,
                layout: 'form',
                border: false,
                items: [linkman]
            }, {
                columnWidth: .6,
                layout: 'form',
                border: false,
                items: [linkmanPhone]
            }]
        }]//, customerLevel]
    });
    
    // load form and assign value to fields
    editFormPanel.form.load({
        url: '/customers/getCustomerByID?id=' + id,
        waitMsg: '正在载入数据...',
        success: function(form, action){
            //debugger;用这个方法进行FF的调试
            sex.setValue(form.reader.jsonData.root[0].sex);
            //customerType.setValue(form.reader.jsonData.root[0].customer_type.customer_type);
            customerType.setRawValue(form.reader.jsonData.root[0].customer_type.customer_type);
            cardType.setRawValue(form.reader.jsonData.root[0].card_type.card_type);
        //cardType.selectByValue(form.reader.jsonData.root[0].card_type.card_type,true);
        //cardType.setValue(form.reader.jsonData.root[0].card_type.card_type);
        //customerLevel.setValue(form.reader.jsonData.root[0].customer_level);
        //Ext.MessageBox.alert('提示信息', birthDay);
        },
        failure: function(form, action){
            Ext.MessageBox.alert('提示信息', '信息加载失败');
        }
    });
    
    // define window and show it in desktop
    var editWindow = new Ext.Window({
        title: '客户信息',
        width: 500,
        height: 250,
        layout: 'fit',
        plain: true,
        bodyStyle: 'padding:5px;',
        buttonAlign: 'center',
        items: editFormPanel,
        //modal: true,
        buttons: [{
            text: '关闭',
            handler: function(){
                editWindow.hide();
            }
        }]
    });
    editWindow.show();
}

//积分维护修改 维护历史积分
function ModPointHis(dataStore, id, name, no){
    var cName = new Ext.form.TextField({
        fieldLabel: '客户',
        allowBlank: true,
        name: 'c_name',
        readOnly: false,
        anchor: '90%',
        value: name
    });
    var cNo = new Ext.form.TextField({
        fieldLabel: '会员卡号',
        allowBlank: true,
        name: 'c_no',
        readOnly: true,
        anchor: '90%',
        value: no
    });
    var point_old = new Ext.form.NumberField({
        fieldLabel: '当前积分',
        name: 'point_old',
        allowBlank: false,
        anchor: '90%'
    });
    var point_his_old = new Ext.form.NumberField({
        fieldLabel: '累计积分',
        name: 'point_his_old',
        allowBlank: false,
        anchor: '90%'
    });
    var price_old = new Ext.form.NumberField({
        fieldLabel: '票款合计',
        name: 'price_old',
        allowBlank: false,
        anchor: '90%'
    });
    var expenditure_old = new Ext.form.NumberField({
        fieldLabel: '累计消费',
        name: 'expenditure_old',
        allowBlank: false,
        anchor: '90%'
    });
    var expenditure_his_old = new Ext.form.NumberField({
        fieldLabel: '历史消费',
        name: 'expenditure_his_old',
        allowBlank: false,
        anchor: '90%'
    });
    var tax_old = new Ext.form.NumberField({
        fieldLabel: '税款合计',
        name: 'tax_old',
        allowBlank: false,
        anchor: '90%'
    });
    var fuel_old = new Ext.form.NumberField({
        fieldLabel: '附加合计',
        name: 'fuel_old',
        allowBlank: false,
        anchor: '90%'
    });
    var formPanel = new Ext.form.FormPanel({
        //baseCls: 'x-plain',
        labelWidth: 60,
        labelAlign: 'right',
        frame: true,
        url: "/customers/saveCustomerPointInfo?id=" + id,
        reader: new Ext.data.JsonReader({
            root: 'root'
        }, ['point_old', 'point_his_old', 'price_old', 'expenditure_old', 'expenditure_his_old', 'tax_old', 'fuel_old']),
        items: [cName, cNo, point_old, point_his_old, price_old, expenditure_old, expenditure_his_old, tax_old, fuel_old]
    });
    formPanel.form.load({
        url: '/customers/getCustomerPointInfo?id=' + id,
        waitMsg: '正在载入数据...',
        success: function(form, action){
        //Ext.MessageBox.alert('提示信息', '信息加载成功！');
        },
        failure: function(form, action){
            Ext.MessageBox.alert('提示信息', '信息加载失败');
        }
    });
    var fixWindow = new Ext.Window({
        title: '初始化历史记录 -- ' + name,
        width: 230,
        height: 330,
        layout: 'fit',
        plain: true,
        bodyStyle: 'padding:5px;',
        buttonAlign: 'center',
        items: formPanel,
        buttons: [{
            text: '保存',
            handler: function(){
                // check form value
                if (formPanel.form.isValid()) {
                    formPanel.form.submit({
                        waitMsg: 'In processing',
                        success: function(form, action){
                            var info = "操作失败，具体失败原因请查询系统日志";
                            if (action.result && action.result.info && action.result.info != "") {
                                info = action.result.info;
                            }
                            Ext.MessageBox.alert('操作信息', info);
                            if (info.indexOf("成功") >= 0) {
                                fixWindow.hide();
                                dataStore.reload();
                            }
                        },
                        failure: function(form, action){
                            var info = "操作失败，具体失败原因请查询系统日志";
                            if (action.result && action.result.info && action.result.info != "") {
                                info = action.result.info;
                            }
                            Ext.MessageBox.alert('操作信息', info);
                        }
                    });
                }
                else {
                    Ext.MessageBox.alert('错误消息', '请将必填项信息录入后再提交.');
                }
            }
        }, {
            text: '取消',
            handler: function(){
                fixWindow.hide();
            }
        }]
    });
    fixWindow.show();
}

//提取票号 确认出票
function getTicketNo(current_order_id, dataStore, dataStore2){
    Ext.Ajax.request({
        url: '/orders/outTicketByOrder',
        params: 'orderid=' + current_order_id,
        method: 'POST',
        success: function(result, request){
            if (result.responseText == "成功") {
                Ext.MessageBox.alert('操作成功', "确认出票成功");
                dataStore.baseParams.id = current_order_id;
                dataStore.reload();
                if (dataStore2) {
                    dataStore2.reload();
                }
            }
            else {
                if (result.responseText && result.responseText != "") {
                    Ext.MessageBox.alert('操作失败', result.responseText);
                }
                else {
                    Ext.MessageBox.alert('操作失败', '确认出票失败');
                }
            }
        },
        failure: function(result, request){
            Ext.MessageBox.alert('操作失败', '没有发现操作方法!');
        }
    });
}

//提取PNR信息
function showPnrInfo(id, dataStore){
    var url = "/orders/getPnrInfo?id=" + id;
    var pnrInfoWindow = new Ext.Window({
        layout: 'fit',
        width: 500,
        height: 400,
        //closeAction: 'hide',
        plain: true,
        modal: true,
        title: '提取结果',
        autoLoad: {
            url: url,
            scripts: true
        },
        buttonAlign: 'center',
        buttons: [{
            text: '关闭',
            handler: function(){
                pnrInfoWindow.hide();
                if (dataStore) {
                    dataStore.reload();
                }
            }
        }]
    });
    pnrInfoWindow.show();
}

function joinActivity(id, dataStore, dataStore2){
    var acType = new Ext.form.ComboBox({
        store: new Ext.data.Store({
            reader: new Ext.data.ArrayReader({}, ['value']),
            data: [[ACTIVITY_TYPE_FHY], [ACTIVITY_TYPE_SQTJP], [ACTIVITY_TYPE_SBX], [ACTIVITY_TYPE_SJC], [ACTIVITY_TYPE_TJP]]
        }),
        name: 'activity_type',
        fieldLabel: '活动',
        resiable: true,
        typeAhead: true,
        width: 70,
        handleHeight: 100,
        displayField: 'value',
        valueField: 'value',
        nameField: 'activity_type',
        selectOnFocus: true,
        mode: 'local',
        selectOnFocus: true,
        triggerAction: 'all', //这个属性非常重要,可以在选择一个值以后,依然还显示其它的值.
        readOnly: true,
        allowBlank: false
    });
    
    var activityFormPanel = new Ext.form.FormPanel({
        //baseCls: 'x-plain',
        labelWidth: 55,
        labelAlign: 'right',
        frame: true,
        url: "/orders/saveActivity?id=" + id,
        items: [acType]
    });
    var activityWindow = new Ext.Window({
        title: '参加活动',
        width: 260,
        height: 130,
        layout: 'fit',
        plain: true,
        bodyStyle: 'padding:5px;',
        buttonAlign: 'center',
        items: activityFormPanel,
        buttons: [{
            text: '确定',
            handler: function(){
                if (activityFormPanel.form.isValid()) {
                    activityFormPanel.form.submit({
                        waitMsg: 'In processing',
                        success: function(form, action){
                            var info = "操作失败，具体失败原因请查询系统日志";
                            if (action.result && action.result.info && action.result.info != "") {
                                info = action.result.info;
                            }
                            if (info.indexOf("成功") >= 0) {
                                activityWindow.hide();
                                Ext.MessageBox.alert('操作成功', info);
                                dataStore.reload();
                                if (dataStore2){
                                    dataStore2.reload();
                                }
                            }
                            else {
                                Ext.MessageBox.alert('操作失败', info);
                            }
                        },
                        failure: function(form, action){
                            var info = "操作失败，具体失败原因请查询系统日志";
                            if (action.result && action.result.info && action.result.info != "") {
                                info = action.result.info;
                            }
                            Ext.MessageBox.alert('操作失败', info);
                        }
                    });
                }
            }
        }, {
            text: '取消',
            handler: function(){
                activityWindow.hide();
            }
        }]
    });
    activityWindow.show();
    
}

//---------------------Create Customer------------------------
function CreateCustomer(customerDS, phoneNumber){
    // pre-define fields in the form
    var customerName = new Ext.form.TextField({
        fieldLabel: "<span class='red'>*</span>客户名称",
        allowBlank: false,
        name: 'name',
        anchor: '90%'
    });
    
    var customerNo = new Ext.form.TextField({
        fieldLabel: '会员卡号',
        //allowBlank: false,
        name: 'customer_no',
        anchor: '90%'
    });
    
    var birthDay = new Ext.form.DateField({
        fieldLabel: '生日',
        name: 'birthday',
        format: 'Y-m-d', //格式化日期
        //disabledDays: [0,6],	//不让选择周六，周日
        //disabledDaysText: "周末要休息",
        invalidText: "您输入的日期格式不对，正确格式为2008-01-01",
        allowBlank: true,
        inputType: '2008-01-01',
        anchor: '90%'
    //value:'1975-01-01'
    //maxValue:'1925-01-01'
    });
    var customerType = new Ext.form.ComboBox({
        store: new Ext.data.Store({
            proxy: new Ext.data.HttpProxy({
                url: '/admin/getCustomerTypes'
            }),
            reader: new Ext.data.JsonReader({
                root: 'root',
                id: 'id'
            }, ['id', 'customer_type'])
        }),
        name: 'customer_type',
        loadingText: '正在加载...',
        displayField: 'customer_type',
        valueField: 'id',
        mode: 'remote',
        triggerAction: 'all',
        hiddenName: 'customer_type_id',
        fieldLabel: "<span class='red'>*</span>客户类型",
        emptyText: '请选择...',
        editable: false,
        allowBlank: false,
        width: 70,
        maxHeight: 150,
        tabIndex: 4
    });
    //card type
    var cardType = new Ext.form.ComboBox({
        store: new Ext.data.Store({
            proxy: new Ext.data.HttpProxy({
                url: '/admin/getCardTypes'
            }),
            reader: new Ext.data.JsonReader({
                root: 'root',
                id: 'id'
            }, ['id', 'card_type'])
        }),
        name: 'card_type',
        loadingText: '正在加载...',
        //displayField: 'customer_type',
        displayField: 'card_type',
        valueField: 'id',
        mode: 'remote',
        triggerAction: 'all',
        hiddenName: 'card_type_id',//如果不想提交displayField，则在这儿指定以提交ID的值．
        //hiddenId:'type_id',
        fieldLabel: '证件类型',
        emptyText: '请选择...',
        editable: false,
        //allowBlank: false,
        width: 60,
        maxHeight: 150,
        tabIndex: 4
    });
    // sex combobox
    var sexArray = [['m', '男'], ['f', '女']];
    var sexReader = new Ext.data.ArrayReader({
        id: 0
    }, [{
        name: 'value'
    }, {
        name: 'key'
    }]);
    var sexStore = new Ext.data.Store({
        reader: sexReader
    });
    sexStore.loadData(sexArray);
    var sex = new Ext.form.ComboBox({ //combobox
        name: 'sex',
        fieldLabel: "<span class='red'>*</span>性别",
        resiable: true,
        typeAhead: true,
        handleHeight: 100, //
        displayField: 'key',
        valueField: 'value',
        selectOnFocus: true,
        mode: 'local',
        selectOnFocus: true,
        triggerAction: 'all',//这个属性非常重要,可以在选择一个值以后,依然还显示其它的值.
        readOnly: true,
        allowBlank: false,
        emptyText: '选择类型...',
        store: sexStore, //数据储存到这个comboBox
        anchor: '90%'
    });
    // level combobox
    var levelArray = [['普通会员', '普通会员'], ['个人客户', '个人客户'], ['VIP', 'VIP'], ['集团客户', '集团客户']];
    var levelReader = new Ext.data.ArrayReader({
        id: 0
    }, [{
        name: 'value'
    }, {
        name: 'key'
    }]);
    var levelStore = new Ext.data.Store({
        reader: levelReader
    });
    levelStore.loadData(levelArray);
    var customerLevel = new Ext.form.ComboBox({ //combobox
        name: 'customer_level',
        fieldLabel: '客户级别',
        resiable: true,
        typeAhead: true,
        handleHeight: 100, //
        displayField: 'key',
        valueField: 'value',
        selectOnFocus: true,
        mode: 'local',
        triggerAction: 'all',//这个属性非常重要,可以在选择一个值以后,依然还显示其它的值.
        readOnly: true,
        emptyText: '选择类型...',
        store: levelStore //数据储存到这个comboBox
    });
    
    var customerAddress = new Ext.form.TextField({
        fieldLabel: '地址',
        //allowBlank: false,
        name: 'address',
        anchor: '90%'
    });
    var card = new Ext.form.TextField({
        fieldLabel: '证件号码',
        //allowBlank: false,
        name: 'card',
        anchor: '90%'
    });
    var phone = new Ext.form.TextField({
        fieldLabel: "<span class='red'>*</span>电话",
        allowBlank: false,
        name: 'phone',
        anchor: '90%'
    });
    if (phoneNumber) {
        phone.setValue(phoneNumber);
    }
    var linkman = new Ext.form.TextField({
        fieldLabel: '联系人',
        //allowBlank: false,
        name: 'linkman',
        anchor: '90%'
    });
    var linkmanPhone = new Ext.form.TextField({
        fieldLabel: '联系人电话',
        //allowBlank: false,
        name: 'linkman_phone',
        anchor: '90%'
    });
    var formPanel = new Ext.form.FormPanel({
        //baseCls: 'x-plain',
        labelWidth: 75,
        labelAlign: 'right',
        frame: true,
        url: '/customers/addCustomer',
        //defaultType: 'textfield',
        items: [{
            layout: 'column',
            border: false,
            items: [{
                columnWidth: .5,
                layout: 'form',
                border: false,
                items: [customerName]
            }, {
                columnWidth: .5,
                layout: 'form',
                border: false,
                items: [customerNo]
            }]
        }, {
            layout: 'column',
            border: false,
            items: [{
                columnWidth: .5,
                layout: 'form',
                border: false,
                items: [sex]
            }, {
                columnWidth: .5,
                layout: 'form',
                border: false,
                items: [customerType]
            }]
        }, {
            layout: 'column',
            border: false,
            items: [{
                columnWidth: .5,
                layout: 'form',
                border: false,
                items: [phone]
            }, {
                columnWidth: .5,
                layout: 'form',
                border: false,
                items: [birthDay]
            }]
        }, customerAddress, {
            layout: 'column',
            border: false,
            items: [{
                columnWidth: .5,
                layout: 'form',
                border: false,
                items: [cardType]
            }, {
                columnWidth: .5,
                layout: 'form',
                border: false,
                items: [card]
            }]
        }, {
            layout: 'column',
            border: false,
            items: [{
                columnWidth: .5,
                layout: 'form',
                border: false,
                items: [linkman]
            }, {
                columnWidth: .5,
                layout: 'form',
                border: false,
                items: [linkmanPhone]
            }]
        }]//, customerLevel]
    });
    
    // define window and show it in desktop
    var window = new Ext.Window({
        title: '增加新客户',
        minimizable: true,
        maximizable: true,
        width: 500,
        height: 250,
        minWidth: 500,
        minHeight: 250,
        layout: 'fit',
        plain: true,
        bodyStyle: 'padding:5px;',
        buttonAlign: 'center',
        items: formPanel,
        modal: true,
        buttons: [{
            text: '增加',
            handler: function(){
                // check form value
                //身份证验证
                var isCard = true;
                if (card.getValue().length>0&&cardType.getValue()=="1"){
                    if (!isSFZ(card.getValue())){
                        isCard = false;
                    }
                }
                if (formPanel.form.isValid()&&isCard) {
                    Ext.Ajax.request({
                        url: '/customers/addCustomer',
                        params: formPanel.form.getValues(true),
                        method: 'POST',
                        success: function(result, request){
                            if (result.responseText.indexOf("添加客户成功")>=0) {
                                Ext.MessageBox.alert('提示', '增加新客户成功');
                                window.destroy();
                                if (!phoneNumber) {
                                    customerDS.load({
                                        params: {
                                            start: 0,
                                            limit: 10
                                        }
                                    });
                                }
                                else {
                                    phoneshow(phone.getValue());
                                }
                            }
                            else {
                                Ext.MessageBox.alert('消息', result.responseText);
                            }
                        },
                        failure: function(result, request){
                            Ext.MessageBox.alert('Failed', 'Not be found!');
                        }
                    });
                }
                else {
                    Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
                }
            }
        }, {
            text: '取消',
            handler: function(){
                window.destroy();
            }
        }]
    });
    
    window.show();
};

//------------Edit Customer-----------------
function EditCustomer(customerDS, customerGridPanel){
    //Ready common combobox
    var m = customerGridPanel.getSelections();
    if (m.length > 0 && m.length == 1) {
        var selectedId = m[0].get("id");
        // pre-define fields in the form
        var customerName = new Ext.form.TextField({
            fieldLabel: "<span class='red'>*</span>客户名称",
            allowBlank: false,
            name: 'name',
            anchor: '90%'
        });
        
        var customerNo = new Ext.form.TextField({
            fieldLabel: '会员卡号',
            name: 'customer_no',
            anchor: '90%'
        });
        
        //Ready common combobox
        var birthDay = new Ext.form.DateField({
            fieldLabel: '生日',
            name: 'birthday',
            format: 'Y-m-d', //格式化日期
            //disabledDays: [0,6],	//不让选择周六，周日
            //disabledDaysText: "周末要休息",
            invalidText: "您输入的日期格式不对，正确格式为2008-01-01",
            allowBlank: true,
            inputType: '2008-01-01',
            anchor: '90%',
            value: '1975/01/01'
        //maxValue:'1925-01-01'
        });
        var customerType = new Ext.form.ComboBox({
            store: new Ext.data.Store({
                proxy: new Ext.data.HttpProxy({
                    url: '/admin/getCustomerTypes'
                }),
                reader: new Ext.data.JsonReader({
                    root: 'root',
                    id: 'id'
                }, ['id', 'customer_type'])
            }),
            name: 'customer_type',
            loadingText: '正在加载...',
            displayField: 'customer_type',
            valueField: 'id',
            mode: 'remote',
            triggerAction: 'all',
            hiddenName: 'customer_type_id',
            fieldLabel: "<span class='red'>*</span>客户类型",
            emptyText: '请选择...',
            editable: false,
            allowBlank: false,
            width: 70,
            maxHeight: 150,
            tabIndex: 4
        });
        //card type
        var cardType = new Ext.form.ComboBox({
            store: new Ext.data.Store({
                proxy: new Ext.data.HttpProxy({
                    url: '/admin/getCardTypes'
                }),
                reader: new Ext.data.JsonReader({
                    root: 'root',
                    id: 'id'
                }, ['id', 'card_type'])
            }),
            name: 'card_type',
            loadingText: '正在加载...',
            //displayField: 'customer_type',
            displayField: 'card_type',
            valueField: 'id',
            mode: 'remote',
            triggerAction: 'all',
            hiddenName: 'card_type_id',//如果不想提交displayField，则在这儿指定以提交ID的值．
            //hiddenId:'type_id',
            fieldLabel: '证件类型',
            emptyText: '请选择...',
            editable: false,
            allowBlank: false,
            width: 60,
            maxHeight: 150,
            tabIndex: 4
        });
        // sex combobox
        var sexArray = [['m', '男'], ['f', '女']];
        var sexReader = new Ext.data.ArrayReader({
            id: 0
        }, [{
            name: 'value'
        }, {
            name: 'key'
        }]);
        var sexStore = new Ext.data.Store({
            reader: sexReader
        });
        sexStore.loadData(sexArray);
        var sex = new Ext.form.ComboBox({ //combobox
            name: 'sex',
            fieldLabel: "<span class='red'>*</span>性别",
            resiable: true,
            typeAhead: true,
            handleHeight: 100, //
            displayField: 'key',
            valueField: 'value',
            selectOnFocus: true,
            mode: 'local',
            selectOnFocus: true,
            triggerAction: 'all',//这个属性非常重要,可以在选择一个值以后,依然还显示其它的值.
            readOnly: true,
            emptyText: '选择类型...',
            store: sexStore, //数据储存到这个comboBox
            anchor: '90%'
        });
        // level combobox
        var levelArray = [['普通会员', '普通会员'], ['个人客户', '个人客户'], ['VIP', 'VIP'], ['集团客户', '集团客户']];
        var levelReader = new Ext.data.ArrayReader({
            id: 0
        }, [{
            name: 'value'
        }, {
            name: 'key'
        }]);
        var levelStore = new Ext.data.Store({
            reader: levelReader
        });
        levelStore.loadData(levelArray);
        var customerLevel = new Ext.form.ComboBox({ //combobox
            name: 'customer_level',
            fieldLabel: '客户级别',
            resiable: true,
            typeAhead: true,
            handleHeight: 100, //
            displayField: 'key',
            valueField: 'value',
            selectOnFocus: true,
            mode: 'local',
            selectOnFocus: true,
            triggerAction: 'all',//这个属性非常重要,可以在选择一个值以后,依然还显示其它的值.
            readOnly: true,
            emptyText: '选择类型...',
            store: levelStore //数据储存到这个comboBox
        });
        
        var customerAddress = new Ext.form.TextField({
            fieldLabel: '地址',
            //allowBlank: false,
            name: 'address',
            anchor: '90%'
        });
        var card = new Ext.form.TextField({
            fieldLabel: '证件号码',
            allowBlank: false,
            name: 'card',
            anchor: '90%'
        });
        var phone = new Ext.form.TextField({
            fieldLabel: "<span class='red'>*</span>电话",
            allowBlank: false,
            name: 'phone',
            anchor: '90%'
        });
        var linkman = new Ext.form.TextField({
            fieldLabel: '联系人',
            //allowBlank: false,
            name: 'linkman',
            anchor: '90%'
        });
        var linkmanPhone = new Ext.form.TextField({
            fieldLabel: '联系人电话',
            //allowBlank: false,
            name: 'linkman_phone',
            anchor: '90%'
        });
        // create form panel
        var editFormPanel = new Ext.form.FormPanel({
            //baseCls: 'x-plain',
            frame: true,
            labelWidth: 75,
            labelAlign: 'right',
            url: '/customers/editCustomer?id=' + selectedId,
            reader: new Ext.data.JsonReader({
                root: 'root'
            }, [{
                name: 'id'
            }, {
                name: 'name'
            }, {
                name: 'customer_no'
            }, {
                name: 'sex'
            }, {
                name: 'phone'
            }, {
                name: 'customer_type'
            }, {
                name: 'address'
            }, {
                name: 'card_type'
            }, {
                name: 'card'
            }, {
                name: 'linkman'
            }, {
                name: 'linkman_phone'
            }, {
                name: 'birthday',
                type: 'date',
                dateFormat: 'Y/m/d'
            }]),
            items: [{
                layout: 'column',
                border: false,
                items: [{
                    columnWidth: .5,
                    layout: 'form',
                    border: false,
                    items: [customerName]
                }, {
                    columnWidth: .5,
                    layout: 'form',
                    border: false,
                    items: [customerNo]
                }]
            }, {
                layout: 'column',
                border: false,
                items: [{
                    columnWidth: .5,
                    layout: 'form',
                    border: false,
                    items: [sex]
                }, {
                    columnWidth: .5,
                    layout: 'form',
                    border: false,
                    items: [customerType]
                }]
            }, {
                layout: 'column',
                border: false,
                items: [{
                    columnWidth: .5,
                    layout: 'form',
                    border: false,
                    items: [phone]
                }, {
                    columnWidth: .5,
                    layout: 'form',
                    border: false,
                    items: [birthDay]
                }]
            }, customerAddress, {
                layout: 'column',
                border: false,
                items: [{
                    columnWidth: .5,
                    layout: 'form',
                    border: false,
                    items: [cardType]
                }, {
                    columnWidth: .5,
                    layout: 'form',
                    border: false,
                    items: [card]
                }]
            }, {
                layout: 'column',
                border: false,
                items: [{
                    columnWidth: .5,
                    layout: 'form',
                    border: false,
                    items: [linkman]
                }, {
                    columnWidth: .5,
                    layout: 'form',
                    border: false,
                    items: [linkmanPhone]
                }]
            }]//, customerLevel]
        });
        
        // load form and assign value to fields
        editFormPanel.form.load({
            url: '/customers/getCustomerByID?id=' + selectedId,
            waitMsg: '正在载入数据...',
            success: function(form, action){
                //debugger;用这个方法进行FF的调试
                sex.setValue(form.reader.jsonData.root[0].sex);
                //customerType.setValue(form.reader.jsonData.root[0].customer_type.customer_type);
                customerType.setRawValue(form.reader.jsonData.root[0].customer_type.customer_type);
                cardType.setRawValue(form.reader.jsonData.root[0].card_type.card_type);
            //cardType.selectByValue(form.reader.jsonData.root[0].card_type.card_type,true);
            //cardType.setValue(form.reader.jsonData.root[0].card_type.card_type);
            //customerLevel.setValue(form.reader.jsonData.root[0].customer_level);
            //Ext.MessageBox.alert('提示信息', birthDay);
            },
            failure: function(form, action){
                Ext.MessageBox.alert('提示信息', '信息加载失败');
            }
        });
        
        // define window and show it in desktop
        var editWindow = new Ext.Window({
            title: '编辑客户',
            width: 500,
            height: 250,
            minWidth: 500,
            minHeight: 250,
            layout: 'fit',
            plain: true,
            bodyStyle: 'padding:5px;',
            buttonAlign: 'center',
            items: editFormPanel,
            modal: true,
            buttons: [{
                text: '提交',
                handler: function(){
                    // check form value
                    if (editFormPanel.form.isValid()) {
                        editFormPanel.form.submit({
                            waitMsg: '处理过程中...',
                            failure: function(result, response){
                                //debugger;
                                Ext.MessageBox.alert('错误提示', response.failureType);//.errorInfo +'提交不成功');
                            },
                            success: function(result, response){
                                if (response.result.info == "编辑用户信息成功") {
                                    Ext.MessageBox.alert('确认', response.result.info);
                                    editWindow.hide();
                                    customerDS.load({
                                        params: {
                                            start: 0,
                                            limit: 10
                                        }
                                    });
                                }
                                else {
                                    Ext.MessageBox.alert('确认', response.result.info);
                                }
                            }
                        });
                    }
                    else {
                        Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
                    }
                }
            }, {
                text: '取消',
                handler: function(){
                    editWindow.hide();
                }
            }]
        });
        editWindow.show();
    }
}

//----------------Delete Customer--------------------------
function DeleteCustomer(customerDS, customerGridPanel){

    // get the selected items
    var m = customerGridPanel.getSelections();
    if (m.length > 0) {
        Ext.MessageBox.confirm('提示', '你真的要删除这些客户吗？', function(btn){
            if (btn == 'yes') {
                var jsonData = "[";
                for (var i = 0, len = m.length; i < len; i++) {
                    var ss = "{\"id\":\"" + m[i].get("id") + "\"}";
                    if (i == 0)
                        jsonData = jsonData + ss;
                    else
                        jsonData = jsonData + "," + ss;
                    customerDS.remove(m[i]);
                }
                jsonData = jsonData + "]";
                //Ext.MessageBox.alert(jsonData);
                customerDS.load({
                    params: {
                        start: 0,
                        limit: 10,
                        delData: jsonData
                    }
                });
            }
        });
    }
    else {
        Ext.MessageBox.alert('错误提示', '要删除客户时，请至少选择一个客户');
    }
};

function getCustomerHistory(customerDS, customerGridPanel){
    var m = customerGridPanel.getSelections();
    if (m.length > 0 && m.length == 1) {
        var selectedId = m[0].get("id");
        if (!customerHistoryWin) {
            customerHistoryWin = new Ext.Window({
                el: 'customerrecord',
                layout: 'fit',
                width: 1000,
                height: 400,
                closeAction: 'hide',
                plain: true,
                modal: true,
                title: '客户资料历史修改记录',
                autoLoad: {
                    url: '/customers/customerHistoryList?customer_id=' + selectedId,
                    scripts: true
                },
                buttons: [{
                    text: '关闭',
                    handler: function(){
                        customerHistoryWin.hide();
                    }
                }]
            });
            customerHistoryWin.show();
        }
        else {
            var url = '/customers/customerHistoryList?customer_id=' + selectedId
            customerHistoryWin.getUpdater().update(url);
            customerHistoryWin.show();
        }
    }
}

//-------------create new hotel order----------------
function CreateHotelOrder(hotelOrderDS, customerID){
    var customerID = new Ext.form.TextField({
        fieldLabel: '客户ID',
        allowBlank: true,
        readOnly: true,
        name: 'customer_id',
        anchor: '90%',
        value: customerID
    });
    
    var roomerName = new Ext.form.TextArea({
        fieldLabel: '房客姓名',
        allowBlank: false,
        name: 'roomer_name',
        anchor: '90%'
    });
    
    var customerPhone = new Ext.form.TextField({
        fieldLabel: '联系电话',
        allowBlank: false,
        name: 'roomer_phone',
        anchor: '90%'
    });
    
    var payType = new Ext.form.ComboBox({
        store: new Ext.data.Store({
            reader: new Ext.data.ArrayReader({}, ['value']),
            data: [[PAY_TYPE_XJ], [PAY_TYPE_SK], [PAY_TYPE_QT], [PAY_TYPE_ZP], [PAY_TYPE_ZZ]]
        }),
        name: 'pay_type',
        fieldLabel: '支付方式',
        resiable: true,
        typeAhead: true,
        width: 100,
        handleHeight: 100,
        displayField: 'value',
        valueField: 'value',
        nameField: 'payType',
        selectOnFocus: true,
        mode: 'local',
        selectOnFocus: true,
        triggerAction: 'all', //这个属性非常重要,可以在选择一个值以后,依然还显示其它的值.
        readOnly: true,
        emptyText: '选择类型...',
        allowBlank: false,
        blankText: "支付方式必须选择",
        value: PAY_TYPE_XJ
    });
    
    var roomType = new Ext.form.TextField({
        fieldLabel: '房间类型',
        allowBlank: false,
        name: 'room_type',
        anchor: '90%'
    });
    
    var roomNumber = new Ext.form.NumberField({
        fieldLabel: '<span class="red">*</span>房间数量',
        allowBlank: false,
        name: 'room_number',
        anchor: '90%'
    });
    
    var peopleNumber = new Ext.form.NumberField({
        fieldLabel: '<span class="red">*</span>入住人数',
        allowBlank: false,
        name: 'people_number',
        anchor: '90%'
    });
    
    var dayNumber = new Ext.form.NumberField({
        fieldLabel: '<span class="red">*</span>入住天数',
        allowBlank: false,
        name: 'day_number',
        anchor: '90%'
    });
    var dateBegin = new Ext.form.DateField({
        fieldLabel: '<span class="red">*</span>开始日期',
        name: 'date_begin',
        id: 'date_begin',
        format: 'Y-m-d', //格式化日期
        width: '80',
        //disabledDays: [0,6],	//不让选择周六，周日
        //disabledDaysText: "周末要休息",
        invalidText: "您输入的日期格式不对，正确格式为2008-01-01",
        allowBlank: false,
        inputType: '2008-01-01',
        anchor: '90%',
        vtype: 'daterange',
        endDateField: 'date_end'
    });
    var dateEnd = new Ext.form.DateField({
        fieldLabel: '<span class="red">*</span>结束日期',
        name: 'date_end',
        id: 'date_end',
        format: 'Y-m-d', //格式化日期
        width: '80',
        //disabledDays: [0,6],	//不让选择周六，周日
        //disabledDaysText: "周末要休息",
        invalidText: "您输入的日期格式不对，正确格式为2008-01-01",
        allowBlank: false,
        inputType: '2008-01-01',
        anchor: '90%',
        vtype: 'daterange',
        startDateField: 'date_begin'
    });
    
    var timeBegin = new Ext.form.TimeField({
        fieldLabel: '最早入住',
        name: 'time_begin',
        minValue: '8:00am',
        increment: 60,
        width: 80,
        maxValue: '6:00pm'
    });
    
    var timeEnd = new Ext.form.TimeField({
        fieldLabel: '最晚入住',
        name: 'time_end',
        minValue: '8:00am',
        increment: 60,
        width: 80,
        maxValue: '6:00pm'
    });
    
    var roomPrice = new Ext.form.NumberField({
        fieldLabel: '<span class="red">*</span>房间售价',
        allowBlank: false,
        name: 'room_price',
        anchor: '90%'
    });
    
    var costPrice = new Ext.form.NumberField({
        fieldLabel: '<span class="red">*</span>房间底价',
        allowBlank: false,
        name: 'cost_price',
        anchor: '90%'
    });
    
    var remark = new Ext.form.TextArea({
        fieldLabel: '备注',
        //allowBlank: false,
        name: 'remark',
        anchor: '90%'
    });
    
    var statusArray = [['已确认', '已确认'], ['已结账', '已结账']];
    var statusReader = new Ext.data.ArrayReader({
        id: 0
    }, [{
        name: 'value'
    }, {
        name: 'key'
    }]);
    var statusStore = new Ext.data.Store({
        reader: statusReader
    });
    statusStore.loadData(statusArray);
    var status = new Ext.form.ComboBox({ //combobox
        name: 'status',
        fieldLabel: '状态',
        resiable: true,
        typeAhead: true,
        handleHeight: 100, //
        displayField: 'key',
        valueField: 'value',
        selectOnFocus: true,
        mode: 'local',
        selectOnFocus: true,
        triggerAction: 'all',//这个属性非常重要,可以在选择一个值以后,依然还显示其它的值.
        readOnly: true,
        emptyText: '选择类型...',
        store: statusStore, //数据储存到这个comboBox
        value: '已确认',
        anchor: '90%'
    });
    
    var formPanel = new Ext.form.FormPanel({
        //baseCls: 'x-plain',
        labelWidth: 75,
        labelAlign: 'right',
        frame: true,
        url: '/orders/addHotelOrder',
        //defaultType: 'textfield',
        items: [{
            layout: 'column',
            border: false,
            items: [{
                columnWidth: .5,
                layout: 'form',
                border: false,
                items: [customerID]
            }, {
                columnWidth: .5,
                layout: 'form',
                border: false,
                items: [status]
            }]
        }, roomerName, {
            layout: 'column',
            border: false,
            items: [{
                columnWidth: .5,
                layout: 'form',
                border: false,
                items: [customerPhone]
            }, {
                columnWidth: .5,
                layout: 'form',
                border: false,
                items: [payType]
            }]
        }, {
            layout: 'column',
            border: false,
            items: [{
                columnWidth: .5,
                layout: 'form',
                border: false,
                items: [roomType]
            }, {
                columnWidth: .5,
                layout: 'form',
                border: false,
                items: [roomNumber]
            }]
        }, {
            layout: 'column',
            border: false,
            items: [{
                columnWidth: .5,
                layout: 'form',
                border: false,
                items: [peopleNumber]
            }, {
                columnWidth: .5,
                layout: 'form',
                border: false,
                items: [dayNumber]
            }]
        }, {
            layout: 'column',
            border: false,
            items: [{
                columnWidth: .5,
                layout: 'form',
                border: false,
                items: [dateBegin]
            }, {
                columnWidth: .5,
                layout: 'form',
                border: false,
                items: [dateEnd]
            }]
        }, {
            layout: 'column',
            border: false,
            items: [{
                columnWidth: .5,
                layout: 'form',
                border: false,
                items: [timeBegin]
            }, {
                columnWidth: .5,
                layout: 'form',
                border: false,
                items: [timeEnd]
            }]
        }, {
            layout: 'column',
            border: false,
            items: [{
                columnWidth: .5,
                layout: 'form',
                border: false,
                items: [roomPrice]
            }, {
                columnWidth: .5,
                layout: 'form',
                border: false,
                items: [costPrice]
            }]
        }, remark]
    });
    // define window and show it in desktop
    var window = new Ext.Window({
        title: '增加酒店订单',
        minimizable: true,
        maximizable: true,
        width: 500,
        height: 420,
        minWidth: 500,
        minHeight: 420,
        layout: 'fit',
        plain: true,
        bodyStyle: 'padding:5px;',
        buttonAlign: 'center',
        items: formPanel,
        modal: true,
        buttons: [{
            text: '增加',
            handler: function(){
                // check form value
                if (formPanel.form.isValid()) {
                    formPanel.form.submit({
                        waitMsg: '处理过程中...',
                        failure: function(result, response){
                            //debugger;
                            Ext.MessageBox.alert('错误提示', response.failureType);//.errorInfo +'提交不成功');
                        },
                        success: function(result, response){
                            if (response.result.info == "添加酒店订单成功") {
                                Ext.MessageBox.alert('确认', response.result.info);
                                window.destroy();
                                hotelOrderDS.load({
                                    params: {
                                        start: 0,
                                        limit: 10
                                    }
                                });
                            }
                            else {
                                Ext.MessageBox.alert('确认', response.result.info);
                            }
                        }
                    });
                }
                else {
                    Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
                }
            }
        }, {
            text: '取消',
            handler: function(){
                window.destroy();
            }
        }]
    });
    window.show();
}

//-------------create new hotel order----------------
function EditHotelOrder(hotelOrderDS, hotelOrderGridPanel){
    var m = hotelOrderGridPanel.getSelections();
    if (m.length == 1) {
        var selectedId = m[0].get("id");
        
        var customerID = new Ext.form.TextField({
            fieldLabel: '客户ID',
            allowBlank: true,
            readOnly: true,
            name: 'customer_id',
            anchor: '90%',
            value: customerID
        });
        
        var roomerName = new Ext.form.TextArea({
            fieldLabel: '房客姓名',
            allowBlank: false,
            name: 'roomer_name',
            anchor: '90%'
        });
        
        var customerPhone = new Ext.form.TextField({
            fieldLabel: '联系电话',
            allowBlank: false,
            name: 'roomer_phone',
            anchor: '90%'
        });
        
        var payType = new Ext.form.ComboBox({
            store: new Ext.data.Store({
                reader: new Ext.data.ArrayReader({}, ['value']),
                data: [[PAY_TYPE_XJ], [PAY_TYPE_SK], [PAY_TYPE_QT], [PAY_TYPE_ZP], [PAY_TYPE_ZZ]]
            }),
            name: 'pay_type',
            fieldLabel: '支付方式',
            resiable: true,
            typeAhead: true,
            width: 100,
            handleHeight: 100,
            displayField: 'value',
            valueField: 'value',
            nameField: 'payType',
            selectOnFocus: true,
            mode: 'local',
            selectOnFocus: true,
            triggerAction: 'all', //这个属性非常重要,可以在选择一个值以后,依然还显示其它的值.
            readOnly: true,
            emptyText: '选择类型...',
            allowBlank: false,
            blankText: "支付方式必须选择",
            value: PAY_TYPE_XJ
        });
        
        var roomType = new Ext.form.TextField({
            fieldLabel: '房间类型',
            allowBlank: false,
            name: 'room_type',
            anchor: '90%'
        });
        
        var roomNumber = new Ext.form.NumberField({
            fieldLabel: '<span class="red">*</span>房间数量',
            allowBlank: false,
            name: 'room_number',
            anchor: '90%'
        });
        
        var peopleNumber = new Ext.form.NumberField({
            fieldLabel: '<span class="red">*</span>入住人数',
            allowBlank: false,
            name: 'people_number',
            anchor: '90%'
        });
        
        var dayNumber = new Ext.form.NumberField({
            fieldLabel: '<span class="red">*</span>入住天数',
            allowBlank: false,
            name: 'day_number',
            anchor: '90%'
        });
        var dateBegin = new Ext.form.DateField({
            fieldLabel: '<span class="red">*</span>开始日期',
            name: 'date_begin',
            id: 'date_begin',
            format: 'Y-m-d', //格式化日期
            width: '80',
            //disabledDays: [0,6],	//不让选择周六，周日
            //disabledDaysText: "周末要休息",
            invalidText: "您输入的日期格式不对，正确格式为2008-01-01",
            allowBlank: false,
            inputType: '2008-01-01',
            anchor: '90%',
            vtype: 'daterange',
            endDateField: 'date_end'
        });
        var dateEnd = new Ext.form.DateField({
            fieldLabel: '<span class="red">*</span>结束日期',
            name: 'date_end',
            id: 'date_end',
            format: 'Y-m-d', //格式化日期
            width: '80',
            //disabledDays: [0,6],	//不让选择周六，周日
            //disabledDaysText: "周末要休息",
            invalidText: "您输入的日期格式不对，正确格式为2008-01-01",
            allowBlank: false,
            inputType: '2008-01-01',
            anchor: '90%',
            vtype: 'daterange',
            startDateField: 'date_begin'
        });
        
        var timeBegin = new Ext.form.TimeField({
            fieldLabel: '最早入住',
            name: 'time_begin',
            minValue: '8:00am',
            increment: 60,
            width: 80,
            maxValue: '6:00pm'
        });
        
        var timeEnd = new Ext.form.TimeField({
            fieldLabel: '最晚入住',
            name: 'time_end',
            minValue: '8:00am',
            increment: 60,
            width: 80,
            maxValue: '6:00pm'
        });
        
        var roomPrice = new Ext.form.NumberField({
            fieldLabel: '<span class="red">*</span>房间售价',
            allowBlank: false,
            name: 'room_price',
            anchor: '90%'
        });
        
        var costPrice = new Ext.form.NumberField({
            fieldLabel: '<span class="red">*</span>房间底价',
            allowBlank: false,
            name: 'cost_price',
            anchor: '90%'
        });
        
        var remark = new Ext.form.TextArea({
            fieldLabel: '备注',
            //allowBlank: false,
            name: 'remark',
            anchor: '90%'
        });
        
        var statusArray = [['已确认', '已确认'], ['已结账', '已结账']];
        var statusReader = new Ext.data.ArrayReader({
            id: 0
        }, [{
            name: 'value'
        }, {
            name: 'key'
        }]);
        var statusStore = new Ext.data.Store({
            reader: statusReader
        });
        statusStore.loadData(statusArray);
        var status = new Ext.form.ComboBox({ //combobox
            name: 'status',
            fieldLabel: '状态',
            resiable: true,
            typeAhead: true,
            handleHeight: 100, //
            displayField: 'key',
            valueField: 'value',
            selectOnFocus: true,
            mode: 'local',
            selectOnFocus: true,
            triggerAction: 'all',//这个属性非常重要,可以在选择一个值以后,依然还显示其它的值.
            readOnly: true,
            emptyText: '选择类型...',
            store: statusStore, //数据储存到这个comboBox
            anchor: '90%'
        });
        
        var formPanel = new Ext.form.FormPanel({
            //baseCls: 'x-plain',
            labelWidth: 75,
            labelAlign: 'right',
            frame: true,
            url: '/orders/editHotelOrder?id=' + selectedId,
            reader: new Ext.data.JsonReader({
                root: 'root'
            }, [{
                name: 'id'
            }, {
                name: 'roomer_name'
            }, {
                name: 'roomer_phone'
            }, {
                name: 'room_type'
            }, {
                name: 'room_number'
            }, {
                name: 'people_number'
            }, {
                name: 'day_number'
            }, {
                name: 'date_begin',
                type: 'date',
                dateFormat: 'Y/m/d'
            }, {
                name: 'date_end',
                type: 'date',
                dateFormat: 'Y/m/d'
            }, {
                name: 'time_begin'
            }, {
                name: 'time_end'
            }, {
                name: 'room_price'
            }, {
                name: 'cost_price'
            }, {
                name: 'pay_type'
            }, {
                name: 'status'
            }, {
                name: 'remark'
            }, {
                name: 'customer_id'
            }]),
            items: [{
                layout: 'column',
                border: false,
                items: [{
                    columnWidth: .5,
                    layout: 'form',
                    border: false,
                    items: [customerID]
                }, {
                    columnWidth: .5,
                    layout: 'form',
                    border: false,
                    items: [status]
                }]
            }, roomerName, {
                layout: 'column',
                border: false,
                items: [{
                    columnWidth: .5,
                    layout: 'form',
                    border: false,
                    items: [customerPhone]
                }, {
                    columnWidth: .5,
                    layout: 'form',
                    border: false,
                    items: [payType]
                }]
            }, {
                layout: 'column',
                border: false,
                items: [{
                    columnWidth: .5,
                    layout: 'form',
                    border: false,
                    items: [roomType]
                }, {
                    columnWidth: .5,
                    layout: 'form',
                    border: false,
                    items: [roomNumber]
                }]
            }, {
                layout: 'column',
                border: false,
                items: [{
                    columnWidth: .5,
                    layout: 'form',
                    border: false,
                    items: [peopleNumber]
                }, {
                    columnWidth: .5,
                    layout: 'form',
                    border: false,
                    items: [dayNumber]
                }]
            }, {
                layout: 'column',
                border: false,
                items: [{
                    columnWidth: .5,
                    layout: 'form',
                    border: false,
                    items: [dateBegin]
                }, {
                    columnWidth: .5,
                    layout: 'form',
                    border: false,
                    items: [dateEnd]
                }]
            }, {
                layout: 'column',
                border: false,
                items: [{
                    columnWidth: .5,
                    layout: 'form',
                    border: false,
                    items: [timeBegin]
                }, {
                    columnWidth: .5,
                    layout: 'form',
                    border: false,
                    items: [timeEnd]
                }]
            }, {
                layout: 'column',
                border: false,
                items: [{
                    columnWidth: .5,
                    layout: 'form',
                    border: false,
                    items: [roomPrice]
                }, {
                    columnWidth: .5,
                    layout: 'form',
                    border: false,
                    items: [costPrice]
                }]
            }, remark]
        });
        
        // load form and assign value to fields
        formPanel.form.load({
            url: '/orders/getHotelOrderByID?id=' + selectedId,
            waitMsg: '正在载入数据...',
            success: function(form, action){
            },
            failure: function(form, action){
                Ext.MessageBox.alert('提示信息', '信息加载失败');
            }
        });
        
        // define window and show it in desktop
        var window = new Ext.Window({
            title: '编辑酒店订单',
            minimizable: true,
            maximizable: true,
            width: 500,
            height: 400,
            minWidth: 500,
            minHeight: 400,
            layout: 'fit',
            plain: true,
            bodyStyle: 'padding:5px;',
            buttonAlign: 'center',
            items: formPanel,
            modal: true,
            buttons: [{
                text: '保存',
                handler: function(){
                    // check form value
                    if (formPanel.form.isValid()) {
                        formPanel.form.submit({
                            waitMsg: '处理过程中...',
                            failure: function(result, response){
                                //debugger;
                                Ext.MessageBox.alert('错误提示', response.failureType);//.errorInfo +'提交不成功');
                            },
                            success: function(result, response){
                                if (response.result.info == "编辑酒店订单成功") {
                                    Ext.MessageBox.alert('确认', response.result.info);
                                    window.destroy();
                                    hotelOrderDS.load({
                                        params: {
                                            start: 0,
                                            limit: 10
                                        }
                                    });
                                }
                                else {
                                    Ext.MessageBox.alert('确认', response.result.info);
                                }
                            }
                        });
                    }
                    else {
                        Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
                    }
                }
            }, {
                text: '取消',
                handler: function(){
                    window.destroy();
                }
            }]
        });
        window.show();
    }
}

//----------------Delete Hotel Order--------------------------
function DeleteHotelOrder(hotelOrderDS, hotelOrderGridPanel){
    // get the selected items
    var m = hotelOrderGridPanel.getSelections();
    if (m.length > 0) {
        Ext.MessageBox.confirm('提示', '你真的要删除这些酒店订单吗？', function(btn){
            if (btn == 'yes') {
                var jsonData = "[";
                for (var i = 0, len = m.length; i < len; i++) {
                    var ss = "{\"id\":\"" + m[i].get("id") + "\"}";
                    if (i == 0)
                        jsonData = jsonData + ss;
                    else
                        jsonData = jsonData + "," + ss;
                    hotelOrderDS.remove(m[i]);
                }
                jsonData = jsonData + "]";
                //Ext.MessageBox.alert(jsonData);
                hotelOrderDS.load({
                    params: {
                        start: 0,
                        limit: 10,
                        delData: jsonData
                    }
                });
            }
        });
    }
    else {
        Ext.MessageBox.alert('错误提示', '要删除客户时，请至少选择一个客户');
    }
}

function getChatRecordList(userDS, userGridPanel){
    var m = userGridPanel.getSelections();
    if (m.length > 0 && m.length == 1) {
        var selectedId = m[0].get("id");
        if (!chatRecordWin) {
            chatRecordWin = new Ext.Window({
                el: 'chatrecord',
                layout: 'fit',
                width: 1000,
                height: 400,
                closeAction: 'hide',
                plain: true,
                modal: true,
                title: '员工通信记录',
                autoLoad: {
                    url: '/users/chatRecordList?user_id=' + selectedId,
                    scripts: true
                },
                buttons: [{
                    text: '关闭',
                    handler: function(){
                        chatRecordWin.hide();
                    }
                }]
            });
            chatRecordWin.show();
        }
        else {
            var url = '/users/chatRecordList?user_id=' + selectedId
            chatRecordWin.getUpdater().update(url);
            chatRecordWin.show();
        }
    }
}

function getSMSRecordList(userDS, userGridPanel){
    var m = userGridPanel.getSelections();
    if (m.length > 0 && m.length == 1) {
        var selectedId = m[0].get("id");
        if (!smsRecordWin) {
            smsRecordWin = new Ext.Window({
                el: 'smsrecord',
                layout: 'fit',
                width: 1000,
                height: 400,
                closeAction: 'hide',
                plain: true,
                modal: true,
                title: '员工短信记录',
                autoLoad: {
                    url: '/users/smsRecordList?user_id=' + selectedId,
                    scripts: true
                },
                buttons: [{
                    text: '关闭',
                    handler: function(){
                        smsRecordWin.hide();
                    }
                }]
            });
            smsRecordWin.show();
        }
        else {
            var url = '/users/smsRecordList?user_id=' + selectedId
            smsRecordWin.getUpdater().update(url);
            smsRecordWin.show();
        }
    }
}

//------------Edit User-----------------
function EditUser(dataStore, userGridPanel){//selectedId
    // pre-define fields in the form
    //Ext.MessageBox.alert('Confirm',selectedId);
    var m = userGridPanel.getSelections();
    if (m.length > 0 && m.length == 1) {
        var selectedId = m[0].get("id");
        var username = new Ext.form.TextField({
            fieldLabel: '姓名',
            allowBlank: false,
            name: 'user_name',
            anchor: '90%'
        });
        
        var password = new Ext.form.TextField({
            fieldLabel: '密码',
            allowBlank: false,
            name: 'password',
            anchor: '90%'
        });
        
        var employee_no = new Ext.form.TextField({
            fieldLabel: '员工ID',
            allowBlank: false,
            name: 'employee_no',
            anchor: '90%'
        });
        
        var loginid = new Ext.form.TextField({
            fieldLabel: '登录ID',
            allowBlank: false,
            name: 'login_id',
            anchor: '90%'
        });
        var usertype = new Ext.form.TextField({
            fieldLabel: '员工类别',
            allowBlank: false,
            name: 'user_type',
            anchor: '90%'
        });
        
        var userTypeArray = [['员工', '员工'], ['话务员', '话务员'], ['送票员', '送票员']];
        var userTypeReader = new Ext.data.ArrayReader({
            id: 0
        }, [{
            name: 'value'
        }, {
            name: 'key'
        }]);
        var userTypeStore = new Ext.data.Store({
            reader: userTypeReader
        });
        userTypeStore.loadData(userTypeArray);
        var userType = new Ext.form.ComboBox({ //combobox
            name: 'user_type',
            fieldLabel: '员工类别',
            resiable: true,
            typeAhead: true,
            allowBlank: false,
            handleHeight: 100, //
            displayField: 'key',
            valueField: 'value',
            //nameField: 'customer_type',
            selectOnFocus: true,
            mode: 'local',
            selectOnFocus: true,
            triggerAction: 'all',//这个属性非常重要,可以在选择一个值以后,依然还显示其它的值.
            readOnly: true,
            emptyText: '选择类型...',
            store: userTypeStore //数据储存到这个comboBox
        });
        //Department type
        var department = new Ext.form.ComboBox({
            store: new Ext.data.Store({
                proxy: new Ext.data.HttpProxy({
                    url: '/admin/getDepartments'
                }),
                reader: new Ext.data.JsonReader({
                    root: 'root',
                    id: 'id'
                }, ['id', 'name'])
            }),
            name: 'department',
            loadingText: '正在加载...',
            displayField: 'name',
            valueField: 'id',
            mode: 'remote',
            triggerAction: 'all',
            hiddenName: 'department_id',//如果不想提交displayField，则在这儿指定以提交ID的值
            fieldLabel: '部门',
            emptyText: '请选择...',
            editable: false,
            allowBlank: false,
            width: 100,
            maxHeight: 150,
            tabIndex: 4
        });
        
        var etermName = new Ext.form.TextField({
            fieldLabel: 'ET用户名',
            //allowBlank: false,
            name: 'eterm_name',
            anchor: '90%'
        });
        
        var etermPassword = new Ext.form.TextField({
            fieldLabel: 'ET密码',
            //allowBlank: false,
            name: 'eterm_pswd',
            anchor: '90%'
        });
        
        
        // create form panel
        var editFormPanel = new Ext.form.FormPanel({
            baseCls: 'x-plain',
            labelWidth: 75,
            url: '/users/editUser?id=' + selectedId,
            reader: new Ext.data.JsonReader({
                root: 'root'
            }, ['id', 'user_name', 'password', 'employee_no', 'login_id', 'user_type', 'department']),
            reader: new Ext.data.JsonReader({
                root: 'root',
                totalProperty: 'totalProperty',
                id: 'id'
            }, [{
                name: 'id'
            }, {
                name: 'user_name'
            }, {
                name: 'password'
            }, {
                name: 'employee_no'
            }, {
                name: 'login_id'
            }, {
                name: 'user_type'
            }, {
                name: 'department',
                mapping: 'department.name'
            }, {
                name: 'eterm_name'
            }, {
                name: 'eterm_pswd'
            }]),
            items: [username, loginid, password, employee_no, userType, department, etermName, etermPassword]
        });
        
        // load form and assign value to fields
        editFormPanel.form.load({
            url: '/users/getUserByID?id=' + selectedId,
            waitMsg: '正在载入数据...',
            success: function(form, action){
                //Ext.MessageBox.alert('提示信息', '信息加载成功！');
                department.setRawValue(form.reader.jsonData.root[0].department.name);
                userType.setValue(form.reader.jsonData.root[0].user_type);
            },
            failure: function(form, action){
                Ext.MessageBox.alert('提示信息', '信息加载失败');
            }
        });
        
        // define window and show it in desktop
        var editWindow = new Ext.Window({
            title: '编辑用户',
            width: 300,
            height: 280,
            minWidth: 300,
            minHeight: 280,
            layout: 'fit',
            plain: true,
            bodyStyle: 'padding:5px;',
            buttonAlign: 'center',
            items: editFormPanel,
            modal: true,
            buttons: [{
                text: '提交',
                handler: function(){
                    // check form value
                    if (editFormPanel.form.isValid()) {
                        editFormPanel.form.submit({
                            params: {
                                id: selectedId
                            },
                            waitMsg: '处理过程中...',
                            failure: function(form, action){
                                //debugger;
                                Ext.MessageBox.alert('错误提示', action.failureType);//.errorInfo +'提交不成功');
                            },
                            success: function(form, action){
                                Ext.MessageBox.alert('确认', '提交成功');
                                editWindow.hide();
                                dataStore.load({
                                    params: {
                                        start: 0,
                                        limit: 10
                                    }
                                });
                            }
                        });
                    }
                    else {
                        Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
                    }
                }
            }, {
                text: '取消',
                handler: function(){
                    editWindow.hide();
                }
            }]
        });
        editWindow.show();
    }
    else {
        Ext.MessageBox.alert('Confirm', "请先选择一条要编辑记录");
    }
}

//---------------------Create User------------------------
function CreateUser(dataStore){

    // pre-define fields in the form
    var username = new Ext.form.TextField({
        fieldLabel: '姓名',
        allowBlank: false,
        name: 'user_name',
        anchor: '90%'
    });
    
    var password = new Ext.form.TextField({
        fieldLabel: '密码',
        allowBlank: false,
        name: 'password',
        anchor: '90%'
    });
    
    var employee_no = new Ext.form.TextField({
        fieldLabel: '员工ID',
        allowBlank: false,
        name: 'employee_no',
        anchor: '90%'
    });
    
    var loginid = new Ext.form.TextField({
        fieldLabel: '登录ID',
        allowBlank: false,
        name: 'login_id',
        anchor: '90%'
    });
    
    var userTypeArray = [['员工', '员工'], ['话务员', '话务员'], ['送票员', '送票员']];
    var userTypeReader = new Ext.data.ArrayReader({
        id: 0
    }, [{
        name: 'value'
    }, {
        name: 'key'
    }]);
    var userTypeStore = new Ext.data.Store({
        reader: userTypeReader
    });
    userTypeStore.loadData(userTypeArray);
    var userType = new Ext.form.ComboBox({ //combobox
        name: 'user_type',
        fieldLabel: '用户类型',
        allowBlank: false,
        resiable: true,
        typeAhead: true,
        handleHeight: 100, //
        displayField: 'key',
        valueField: 'value',
        //nameField: 'customer_type',
        selectOnFocus: true,
        mode: 'local',
        selectOnFocus: true,
        triggerAction: 'all',//这个属性非常重要,可以在选择一个值以后,依然还显示其它的值.
        readOnly: true,
        emptyText: '选择类型...',
        store: userTypeStore //数据储存到这个comboBox
    });
    //Department type
    var department = new Ext.form.ComboBox({
        store: new Ext.data.Store({
            proxy: new Ext.data.HttpProxy({
                url: '/admin/getDepartments'
            }),
            reader: new Ext.data.JsonReader({
                root: 'root',
                id: 'id'
            }, ['id', 'name'])
        }),
        name: 'department',
        loadingText: '正在加载...',
        displayField: 'name',
        valueField: 'id',
        mode: 'remote',
        triggerAction: 'all',
        hiddenName: 'department_id',//如果不想提交displayField，则在这儿指定以提交ID的值
        fieldLabel: '部门',
        emptyText: '请选择...',
        editable: false,
        allowBlank: false,
        width: 100,
        maxHeight: 150,
        tabIndex: 4
    });
    
    var etermName = new Ext.form.TextField({
        fieldLabel: 'ET用户名',
        //allowBlank: false,
        name: 'eterm_name',
        anchor: '90%'
    });
    
    var etermPassword = new Ext.form.TextField({
        fieldLabel: 'ET密码',
        //allowBlank: false,
        name: 'eterm_pswd',
        anchor: '90%'
    });
    var formPanel = new Ext.form.FormPanel({
    
        baseCls: 'x-plain',
        labelWidth: 75,
        url: '/users/addUser',
        defaultType: 'textfield',
        
        items: [username, loginid, password, employee_no, userType, department, etermName, etermPassword]
    });
    
    // define window and show it in desktop
    var window = new Ext.Window({
        title: '增加新员工',
        width: 300,
        height: 280,
        minWidth: 300,
        minHeight: 280,
        layout: 'fit',
        plain: true,
        bodyStyle: 'padding:5px;',
        buttonAlign: 'center',
        items: formPanel,
        modal: true,
        buttons: [{
            text: '增加',
            handler: function(){
                // check form value
                if (formPanel.form.isValid()) {
                    formPanel.form.submit({
                        waitMsg: 'In processing',
                        success: function(form, action){
                            Ext.MessageBox.alert('Confirm', '提交成功');
                            window.destroy();
                            dataStore.load({
                                params: {
                                    start: 0,
                                    limit: 10
                                }
                            });
                        },
                        failure: function(form, action){
                            Ext.MessageBox.alert('提交错误消息', '提交失败');
                        }
                    });
                }
                else {
                    Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
                }
            }
        }, {
            text: '取消',
            handler: function(){
                window.destroy();
            }
        }]
    });
    
    window.show();
};
//----------------Delete User--------------------------
function DeleteUser(dataStore, userGridPanel){

    // get the selected items
    var m = userGridPanel.getSelections();
    if (m.length > 0) {
        Ext.MessageBox.confirm('提示', '你真的要删除这些用户吗？', function(btn){
            if (btn == 'yes') {
                var jsonData = "[";
                for (var i = 0, len = m.length; i < len; i++) {
                    var ss = "{\"id\":\"" + m[i].get("id") + "\"}";
                    if (i == 0)
                        jsonData = jsonData + ss;
                    else
                        jsonData = jsonData + "," + ss;
                    dataStore.remove(m[i]);
                }
                jsonData = jsonData + "]";
                //Ext.MessageBox.alert(jsonData);
                dataStore.load({
                    params: {
                        start: 0,
                        limit: 10,
                        delData: jsonData
                    }
                });
            }
        });
    }
    else {
        Ext.MessageBox.alert('错误提示', '要删除用户时，请至少选择一个用户');
    }
};

function deletePolicy(policyDS, policyGridPanel){
    // get the selected items
    var m = policyGridPanel.getSelections();
    if (m.length > 0) {
        Ext.MessageBox.confirm('提示', '你真的要删除这些政策吗？', function(btn){
            if (btn == 'yes') {
                var jsonData = "[";
                for (var i = 0, len = m.length; i < len; i++) {
                    var ss = "{\"id\":\"" + m[i].get("id") + "\"}";
                    if (i == 0)
                        jsonData = jsonData + ss;
                    else
                        jsonData = jsonData + "," + ss;
                    policyDS.remove(m[i]);
                }
                jsonData = jsonData + "]";
                //Ext.MessageBox.alert(jsonData);
                policyDS.load({
                    params: {
                        start: 0,
                        limit: 10,
                        delData: jsonData
                    }
                });
            }
        });
    }
    else {
        Ext.MessageBox.alert('错误提示', '要删除政策时，请至少选择一个政策');
    }
}


//---------------------Create right------------------------
function Createright(dataStore){
    var controllerName = new Ext.form.TextField({
        fieldLabel: 'Controller',
        allowBlank: false,
        name: 'controller_name',
        anchor: '90%'
    });
    var actionName = new Ext.form.TextField({
        fieldLabel: 'Action',
        allowBlank: false,
        name: 'action_name',
        anchor: '90%'
    });
    var description = new Ext.form.TextField({
        fieldLabel: 'Description',
        allowBlank: false,
        name: 'description',
        anchor: '90%'
    });
    
    var formPanel = new Ext.form.FormPanel({
        baseCls: 'x-plain',
        labelWidth: 75,
        url: '/rights/addRight',
        defaultType: 'textfield',
        items: [controllerName, actionName, description]
    });
    
    // define window and show it in desktop
    var window = new Ext.Window({
        title: '增加新权限',
        width: 300,
        height: 200,
        minWidth: 300,
        minHeight: 250,
        layout: 'fit',
        plain: true,
        bodyStyle: 'padding:5px;',
        buttonAlign: 'center',
        items: formPanel,
        modal: true,
        buttons: [{
            text: '增加',
            handler: function(){
                // check form value
                if (formPanel.form.isValid()) {
                    formPanel.form.submit({
                        waitMsg: 'In processing',
                        success: function(form, action){
                            Ext.MessageBox.alert('Confirm', '提交成功');
                            window.destroy();
                            dataStore.load({
                                params: {
                                    start: 0,
                                    limit: 10
                                }
                            });
                        },
                        failure: function(form, action){
                            Ext.MessageBox.alert('提交错误消息', '提交失败');
                        }
                    });
                }
                else {
                    Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
                }
            }
        }, {
            text: '取消',
            handler: function(){
                window.destroy();
            }
        }]
    });
    
    window.show();
};
//----------------Delete right--------------------------
function Deleteright(dataStore, rightGridPanel){

    // get the selected items
    var m = rightGridPanel.getSelections();
    if (m.length > 0) {
        Ext.MessageBox.confirm('提示', '你真的要删除这些用户吗？', function(btn){
            if (btn == 'yes') {
                var jsonData = "[";
                for (var i = 0, len = m.length; i < len; i++) {
                    var ss = "{\"id\":\"" + m[i].get("id") + "\"}";
                    if (i == 0)
                        jsonData = jsonData + ss;
                    else
                        jsonData = jsonData + "," + ss;
                    dataStore.remove(m[i]);
                }
                jsonData = jsonData + "]";
                //Ext.MessageBox.alert(jsonData);
                dataStore.load({
                    params: {
                        start: 0,
                        limit: 10,
                        delData: jsonData
                    }
                });
            }
        });
    }
    else {
        Ext.MessageBox.alert('错误提示', '要删除用户时，请至少选择一个用户');
    }
};

//------------Edit right-----------------
function EditRight(dataStore, selectedId){
    var controllerName = new Ext.form.TextField({
        fieldLabel: 'Controller',
        allowBlank: false,
        name: 'controller_name',
        anchor: '90%'
    });
    var actionName = new Ext.form.TextField({
        fieldLabel: 'Action',
        allowBlank: false,
        name: 'action_name',
        anchor: '90%'
    });
    var description = new Ext.form.TextField({
        fieldLabel: 'Description',
        allowBlank: false,
        name: 'description',
        anchor: '90%'
    });
    // create form panel
    var editFormPanel = new Ext.form.FormPanel({
        baseCls: 'x-plain',
        labelWidth: 75,
        url: '/rights/editRight?id=' + selectedId,
        reader: new Ext.data.JsonReader({
            root: 'root'
        }, [{
            name: 'id'
        }, {
            name: 'controller_name'
        }, {
            name: 'action_name'
        }, {
            name: 'description'
        }]),
        
        items: [controllerName, actionName, description]
    });
    
    // load form and assign value to fields
    editFormPanel.form.load({
        url: '/rights/getRightByID?id=' + selectedId,
        waitMsg: '正在载入数据...',
        success: function(form, action){
        //debugger;用这个方法进行FF的调试
        //Ext.MessageBox.alert('提示信息', '信息加载成功！');
        },
        failure: function(form, action){
            Ext.MessageBox.alert('提示信息', '信息加载失败');
        }
    });
    
    // define window and show it in desktop
    var editRightWindow = new Ext.Window({
        title: '编辑用户',
        width: 300,
        height: 200,
        minWidth: 300,
        minHeight: 250,
        layout: 'fit',
        plain: true,
        bodyStyle: 'padding:5px;',
        buttonAlign: 'center',
        items: editFormPanel,
        modal: true,
        buttons: [{
            text: '提交',
            handler: function(){
                // check form value
                if (editFormPanel.form.isValid()) {
                    editFormPanel.form.submit({
                        params: {
                            id: selectedId
                        },
                        waitMsg: '处理过程中...',
                        success: function(form, action){
                            Ext.MessageBox.alert('确认', '提交成功');
                            editRightWindow.hide();
                            dataStore.load({
                                params: {
                                    start: 0,
                                    limit: 10
                                }
                            });
                        },
                        failure: function(form, action){
                            //debugger;
                            Ext.MessageBox.alert('错误提示', action.failureType);//.errorInfo +'提交不成功');
                        }
                    });
                }
                else {
                    Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
                }
            }
        }, {
            text: '取消',
            handler: function(){
                editRightWindow.hide();
            }
        }]
    });
    editRightWindow.show();
}

//---------------------Create Airport------------------------
function CreateAirport(dataStore){

    // pre-define fields in the form
    var airportname = new Ext.form.TextField({
        fieldLabel: '空港名称',
        allowBlank: false,
        name: 'airport_name',
        anchor: '90%'
    });
    var airportcode = new Ext.form.TextField({
        fieldLabel: '空港代码',
        allowBlank: false,
        name: 'airport_code',
        anchor: '90%'
    });
    var formPanel = new Ext.form.FormPanel({
        baseCls: 'x-plain',
        labelWidth: 75,
        url: '/admin/addAirport',
        defaultType: 'textfield',
        items: [airportname, airportcode]
    });
    
    // define window and show it in desktop
    var addAirportWindow = new Ext.Window({
        title: '增加空港管理',
        width: 300,
        height: 150,
        minWidth: 300,
        minHeight: 150,
        layout: 'fit',
        plain: true,
        bodyStyle: 'padding:5px;',
        buttonAlign: 'center',
        items: formPanel,
        modal: true,
        buttons: [{
            text: '增加',
            handler: function(){
                // check form value
                if (formPanel.form.isValid()) {
                    formPanel.form.submit({
                        waitMsg: 'In processing',
                        success: function(form, action){
                            Ext.MessageBox.alert('提示', '提交成功');
                            addAirportWindow.destroy();
                            dataStore.load();
                        },
                        failure: function(form, action){
                            Ext.MessageBox.alert('提交错误消息', '提交失败');
                        }
                    });
                }
                else {
                    Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
                }
            }
        }, {
            text: '取消',
            handler: function(){
                addAirportWindow.destroy();
            }
        }]
    });
    
    addAirportWindow.show();
};
//----------------Delete Airport--------------------------
function DeleteAirport(dataStore, gridPanel){
    // get the selected items
    var m = gridPanel.getSelections();
    if (m.length > 0) {
        Ext.MessageBox.confirm('提示', '你真的要删除这些空港管理吗？', function(btn){
            if (btn == 'yes') {
                var jsonData = "[";
                for (var i = 0, len = m.length; i < len; i++) {
                    var ss = "{\"id\":\"" + m[i].get("id") + "\"}";
                    if (i == 0)
                        jsonData = jsonData + ss;
                    else
                        jsonData = jsonData + "," + ss;
                    dataStore.remove(m[i]);
                }
                jsonData = jsonData + "]";
                //Ext.MessageBox.alert(jsonData);
                dataStore.load({
                    params: {
                        delData: jsonData
                    }
                });
            }
        });
    }
    else {
        Ext.MessageBox.alert('错误提示', '要删除空港管理时，请至少选择一个空港管理');
    }
};

//------------Edit Airport-----------------
function EditAirport(dataStore, gridPanel){//selectedId
    // pre-define fields in the form
    //Ext.MessageBox.alert('提示',selectedId);
    var m = gridPanel.getSelections();
    if (m.length > 0 && m.length == 1) {
        var selectedId = m[0].get("id");
        var airportname = new Ext.form.TextField({
            fieldLabel: '空港管理',
            allowBlank: false,
            name: 'airport_name',
            anchor: '90%'
        });
        var airportcode = new Ext.form.TextField({
            fieldLabel: '空港管理',
            allowBlank: false,
            name: 'airport_code',
            anchor: '90%'
        });
        // create form panel
        var editFormPanel = new Ext.form.FormPanel({
            baseCls: 'x-plain',
            labelWidth: 75,
            url: '/admin/editAirport?id=' + selectedId,
            reader: new Ext.data.JsonReader({
                root: 'root'
            }, ['id', 'airport_name', 'airport_code']),
            
            items: [airportname, airportcode]
        });
        
        // load form and assign value to fields
        editFormPanel.form.load({
            url: '/admin/getAirportByID?id=' + selectedId,
            waitMsg: '正在载入数据...',
            success: function(form, action){
            //Ext.MessageBox.alert('提示信息', '信息加载成功！');
            },
            failure: function(form, action){
                Ext.MessageBox.alert('提示信息', '信息加载失败');
            }
        });
        
        // define window and show it in desktop
        var editAirportWindow = new Ext.Window({
            title: '编辑空港管理',
            width: 300,
            height: 150,
            minWidth: 300,
            minHeight: 150,
            layout: 'fit',
            plain: true,
            bodyStyle: 'padding:5px;',
            buttonAlign: 'center',
            items: editFormPanel,
            modal: true,
            buttons: [{
                text: '提交',
                handler: function(){
                    // check form value
                    if (editFormPanel.form.isValid()) {
                        editFormPanel.form.submit({
                            params: {
                                id: selectedId
                            },
                            waitMsg: '处理过程中...',
                            failure: function(form, action){
                                //debugger;
                                Ext.MessageBox.alert('错误提示', action.failureType);
                            },
                            success: function(form, action){
                                Ext.MessageBox.alert('确认', '提交成功');
                                editAirportWindow.destroy();
                                dataStore.load();
                            }
                        });
                    }
                    else {
                        Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
                    }
                }
            }, {
                text: '取消',
                handler: function(){
                    editAirportWindow.destroy();
                }
            }]
        });
        editAirportWindow.show();
    }
    else {
        Ext.MessageBox.alert('提示', "请先选择一条要编辑记录");
    }
}

//---------------------Create Airways------------------------
function CreateAirways(dataStore){

    // pre-define fields in the form
    var airwaysname = new Ext.form.TextField({
        fieldLabel: '航空公司',
        allowBlank: false,
        name: 'airways_name',
        anchor: '90%'
    });
    var airwayscode = new Ext.form.TextField({
        fieldLabel: '公司代码',
        allowBlank: false,
        name: 'airways_code',
        anchor: '90%'
    });
    var passengercode = new Ext.form.TextField({
        fieldLabel: '客票代码',
        allowBlank: false,
        name: 'passenger_code',
        anchor: '90%'
    });

    var airwayTypeGN = new Ext.form.Radio({
        fieldLabel: '航空公司类型',
        name: 'airways_type',
        id: 'airway_type_gn',
        boxLabel: '国内',
        checked: true,
        inputValue: 'internal'
    });
    var airwayTypeGJ = new Ext.form.Radio({
        name: 'airways_type',
        id: 'airway_type_gj',
        boxLabel: '国际',
        checked: false,
        hideLabel: true,
        inputValue: 'international'
    });
    var formPanel = new Ext.form.FormPanel({
        //baseCls: 'x-plain',
        frame: true,
        labelWidth: 75,
        url: '/admin/addAirways',
        //defaultType: 'textfield',
        items: [airwaysname, airwayscode, passengercode, {
            layout: 'column',
            border: false,
            items: [{
                columnWidth: .5,
                layout: 'form',
                border: false,
                items: [airwayTypeGN]
            }, {
                columnWidth: .5,
                layout: 'form',
                border: false,
                items: [airwayTypeGJ]
            }]
        }]
    });
    
    // define window and show it in desktop
    var window = new Ext.Window({
        title: '增加航空公司',
        width: 300,
        height: 185,
        minWidth: 300,
        minHeight: 185,
        layout: 'fit',
        plain: true,
        bodyStyle: 'padding:5px;',
        buttonAlign: 'center',
        items: formPanel,
        modal: true,
        buttons: [{
            text: '增加',
            handler: function(){
                // check form value
                if (formPanel.form.isValid()) {
                    formPanel.form.submit({
                        waitMsg: 'In processing',
                        success: function(form, action){
                            Ext.MessageBox.alert('提示', '提交成功');
                            window.destroy();
                            dataStore.load();
                        },
                        failure: function(form, action){
                            Ext.MessageBox.alert('提交错误消息', '提交失败');
                        }
                    });
                }
                else {
                    Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
                }
            }
        }, {
            text: '取消',
            handler: function(){
                window.destroy();
            }
        }]
    });
    
    window.show();
};
//----------------Delete Airways--------------------------
function DeleteAirways(dataStore, gridPanel){
    // get the selected items
    var m = gridPanel.getSelections();
    if (m.length > 0) {
        Ext.MessageBox.confirm('提示', '你真的要删除这些航空公司吗？', function(btn){
            if (btn == 'yes') {
                var jsonData = "[";
                for (var i = 0, len = m.length; i < len; i++) {
                    var ss = "{\"id\":\"" + m[i].get("id") + "\"}";
                    if (i == 0)
                        jsonData = jsonData + ss;
                    else
                        jsonData = jsonData + "," + ss;
                    dataStore.remove(m[i]);
                }
                jsonData = jsonData + "]";
                //Ext.MessageBox.alert(jsonData);
                dataStore.load({
                    params: {
                        delData: jsonData
                    }
                });
            }
        });
    }
    else {
        Ext.MessageBox.alert('错误提示', '要删除航空公司时，请至少选择一个航空公司');
    }
};

//------------Edit Airways-----------------
function EditAirways(dataStore, gridPanel){//selectedId
    // pre-define fields in the form
    //Ext.MessageBox.alert('提示',selectedId);
    var m = gridPanel.getSelections();
    if (m.length > 0 && m.length == 1) {
        var selectedId = m[0].get("id");
        var airwaysname = new Ext.form.TextField({
            fieldLabel: '航空公司',
            allowBlank: false,
            name: 'airways_name',
            anchor: '90%'
        });
        var airwayscode = new Ext.form.TextField({
            fieldLabel: '公司代码',
            allowBlank: false,
            name: 'airways_code',
            anchor: '90%'
        });
        var passengercode = new Ext.form.TextField({
            fieldLabel: '客票代码',
            allowBlank: false,
            name: 'passenger_code',
            anchor: '90%'
        });
        var airwayTypeGN = new Ext.form.Radio({
            fieldLabel: '航空公司类型',
            name: 'airways_type',
            id: 'airway_type_gn',
            boxLabel: '国内',
            checked: true,
            inputValue: 'internal'
        });
        var airwayTypeGJ = new Ext.form.Radio({
            name: 'airways_type',
            id: 'airway_type_gj',
            boxLabel: '国际',
            checked: false,
            hideLabel: true,
            inputValue: 'international'
        });
        // create form panel
        var editFormPanel = new Ext.form.FormPanel({
            //baseCls: 'x-plain',
            labelWidth: 75,
            frame:true,
            url: '/admin/editAirways?id=' + selectedId,
            reader: new Ext.data.JsonReader({
                root: 'root'
            }, ['id', 'airways_name', 'airways_code', 'passenger_code', 'airways_type']),
            
            items: [airwaysname, airwayscode, passengercode, {
                layout: 'column',
                border: false,
                items: [{
                    columnWidth: .5,
                    layout: 'form',
                    border: false,
                    items: [airwayTypeGN]
                }, {
                    columnWidth: .5,
                    layout: 'form',
                    border: false,
                    items: [airwayTypeGJ]
                }]
            }]
        });
        
        // load form and assign value to fields
        editFormPanel.form.load({
            url: '/admin/getAirwaysByID?id=' + selectedId,
            waitMsg: '正在载入数据...',
            success: function(form, action){
            //Ext.MessageBox.alert('提示信息', '信息加载成功！');
            },
            failure: function(form, action){
                Ext.MessageBox.alert('提示信息', '信息加载失败');
            }
        });
        
        // define window and show it in desktop
        var editAirwaysWindow = new Ext.Window({
            title: '编辑航空公司',
            width: 300,
            height: 185,
            minWidth: 300,
            minHeight: 185,
            layout: 'fit',
            plain: true,
            bodyStyle: 'padding:5px;',
            buttonAlign: 'center',
            items: editFormPanel,
            modal: true,
            buttons: [{
                text: '提交',
                handler: function(){
                    // check form value
                    if (editFormPanel.form.isValid()) {
                        editFormPanel.form.submit({
                            params: {
                                id: selectedId
                            },
                            waitMsg: '处理过程中...',
                            failure: function(form, action){
                                //debugger;
                                Ext.MessageBox.alert('错误提示', action.failureType);
                            },
                            success: function(form, action){
                                Ext.MessageBox.alert('确认', '提交成功');
                                editAirwaysWindow.destroy();
                                dataStore.load();
                            }
                        });
                    }
                    else {
                        Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
                    }
                }
            }, {
                text: '取消',
                handler: function(){
                    editAirwaysWindow.destroy();
                }
            }]
        });
        editAirwaysWindow.show();
    }
    else {
        Ext.MessageBox.alert('提示', "请先选择一条要编辑记录");
    }
}

//---------------------Create CardType------------------------
function CreateCardType(dataStore){

    // pre-define fields in the form
    var cardtype = new Ext.form.TextField({
        fieldLabel: '证件类型',
        allowBlank: false,
        name: 'card_type',
        anchor: '90%'
    });
    
    var formPanel = new Ext.form.FormPanel({
        baseCls: 'x-plain',
        labelWidth: 75,
        url: '/admin/addCardType',
        defaultType: 'textfield',
        items: [cardtype]
    });
    
    // define window and show it in desktop
    var addCardTypeWindow = new Ext.Window({
        title: '增加证件类型',
        width: 300,
        height: 150,
        minWidth: 300,
        minHeight: 150,
        layout: 'fit',
        plain: true,
        bodyStyle: 'padding:5px;',
        buttonAlign: 'center',
        items: formPanel,
        modal: true,
        buttons: [{
            text: '增加',
            handler: function(){
                // check form value
                if (formPanel.form.isValid()) {
                    formPanel.form.submit({
                        waitMsg: 'In processing',
                        success: function(form, action){
                            Ext.MessageBox.alert('提示', '提交成功');
                            addCardTypeWindow.destroy();
                            dataStore.load();
                        },
                        failure: function(form, action){
                            Ext.MessageBox.alert('提交错误消息', '提交失败');
                        }
                    });
                }
                else {
                    Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
                }
            }
        }, {
            text: '取消',
            handler: function(){
                addCardTypeWindow.destroy();
            }
        }]
    });
    
    addCardTypeWindow.show();
};
//----------------Delete CardType--------------------------
function DeleteCardType(dataStore, gridPanel){
    // get the selected items
    var m = gridPanel.getSelections();
    if (m.length > 0) {
        Ext.MessageBox.confirm('提示', '你真的要删除这些证件类型吗？', function(btn){
            if (btn == 'yes') {
                var jsonData = "[";
                for (var i = 0, len = m.length; i < len; i++) {
                    var ss = "{\"id\":\"" + m[i].get("id") + "\"}";
                    if (i == 0)
                        jsonData = jsonData + ss;
                    else
                        jsonData = jsonData + "," + ss;
                    dataStore.remove(m[i]);
                }
                jsonData = jsonData + "]";
                //Ext.MessageBox.alert(jsonData);
                dataStore.load({
                    params: {
                        delData: jsonData
                    }
                });
            }
        });
    }
    else {
        Ext.MessageBox.alert('错误提示', '要删除证件类型时，请至少选择一个证件类型');
    }
};

//------------Edit CardType-----------------
function EditCardType(dataStore, gridPanel){//selectedId
    // pre-define fields in the form
    //Ext.MessageBox.alert('提示',selectedId);
    var m = gridPanel.getSelections();
    if (m.length > 0 && m.length == 1) {
        var selectedId = m[0].get("id");
        var cardtype = new Ext.form.TextField({
            fieldLabel: '证件类型',
            allowBlank: false,
            name: 'card_type',
            anchor: '90%'
        });
        
        // create form panel
        var editFormPanel = new Ext.form.FormPanel({
            baseCls: 'x-plain',
            labelWidth: 75,
            url: '/admin/editCardType?id=' + selectedId,
            reader: new Ext.data.JsonReader({
                root: 'root'
            }, ['id', 'card_type']),
            
            items: [cardtype]
        });
        
        // load form and assign value to fields
        editFormPanel.form.load({
            url: '/admin/getCardTypeByID?id=' + selectedId,
            waitMsg: '正在载入数据...',
            success: function(form, action){
            //Ext.MessageBox.alert('提示信息', '信息加载成功！');
            },
            failure: function(form, action){
                Ext.MessageBox.alert('提示信息', '信息加载失败');
            }
        });
        
        // define window and show it in desktop
        var editCardTypeWindow = new Ext.Window({
            title: '编辑证件类型',
            width: 300,
            height: 150,
            minWidth: 300,
            minHeight: 150,
            layout: 'fit',
            plain: true,
            bodyStyle: 'padding:5px;',
            buttonAlign: 'center',
            items: editFormPanel,
            modal: true,
            buttons: [{
                text: '提交',
                handler: function(){
                    // check form value
                    if (editFormPanel.form.isValid()) {
                        editFormPanel.form.submit({
                            params: {
                                id: selectedId
                            },
                            waitMsg: '处理过程中...',
                            failure: function(form, action){
                                //debugger;
                                Ext.MessageBox.alert('错误提示', action.failureType);
                            },
                            success: function(form, action){
                                Ext.MessageBox.alert('确认', '提交成功');
                                editCardTypeWindow.hide();
                                dataStore.load();
                            }
                        });
                    }
                    else {
                        Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
                    }
                }
            }, {
                text: '取消',
                handler: function(){
                    editCardTypeWindow.hide();
                }
            }]
        });
        editCardTypeWindow.show();
    }
    else {
        Ext.MessageBox.alert('提示', "请先选择一条要编辑记录");
    }
}

//---------------------Create CostLevel------------------------
function CreateCostLevel(dataStore){

    // pre-define fields in the form
    var costlevel = new Ext.form.TextField({
        fieldLabel: '消费级别',
        allowBlank: false,
        name: 'cost_level',
        anchor: '90%'
    });
    var consumption = new Ext.form.TextField({
        fieldLabel: '消费金额',
        allowBlank: false,
        name: 'consumption',
        anchor: '90%'
    });
    var remark = new Ext.form.TextField({
        fieldLabel: '备注',
        allowBlank: false,
        name: 'remark',
        anchor: '90%'
    });
    var formPanel = new Ext.form.FormPanel({
        baseCls: 'x-plain',
        labelWidth: 75,
        url: '/admin/addCostLevel',
        defaultType: 'textfield',
        items: [costlevel, consumption, remark]
    });
    
    // define window and show it in desktop
    var addCostLevelWindow = new Ext.Window({
        title: '增加消费级别',
        width: 300,
        height: 150,
        minWidth: 300,
        minHeight: 150,
        layout: 'fit',
        plain: true,
        bodyStyle: 'padding:5px;',
        buttonAlign: 'center',
        items: formPanel,
        modal: true,
        buttons: [{
            text: '增加',
            handler: function(){
                // check form value
                if (formPanel.form.isValid()) {
                    formPanel.form.submit({
                        waitMsg: 'In processing',
                        success: function(form, action){
                            Ext.MessageBox.alert('提示', '提交成功');
                            addCostLevelWindow.destroy();
                            dataStore.load();
                        },
                        failure: function(form, action){
                            Ext.MessageBox.alert('提交错误消息', '提交失败');
                        }
                    });
                }
                else {
                    Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
                }
            }
        }, {
            text: '取消',
            handler: function(){
                addCostLevelWindow.destroy();
            }
        }]
    });
    
    addCostLevelWindow.show();
};
//----------------Delete CostLevel--------------------------
function DeleteCostLevel(dataStore, gridPanel){
    // get the selected items
    var m = gridPanel.getSelections();
    if (m.length > 0) {
        Ext.MessageBox.confirm('提示', '你真的要删除这些消费级别吗？', function(btn){
            if (btn == 'yes') {
                var jsonData = "[";
                for (var i = 0, len = m.length; i < len; i++) {
                    var ss = "{\"id\":\"" + m[i].get("id") + "\"}";
                    if (i == 0)
                        jsonData = jsonData + ss;
                    else
                        jsonData = jsonData + "," + ss;
                    dataStore.remove(m[i]);
                }
                jsonData = jsonData + "]";
                //Ext.MessageBox.alert(jsonData);
                dataStore.load({
                    params: {
                        delData: jsonData
                    }
                });
            }
        });
    }
    else {
        Ext.MessageBox.alert('错误提示', '要删除消费级别时，请至少选择一个消费级别');
    }
};

//------------Edit CostLevel-----------------
function EditCostLevel(dataStore, gridPanel){//selectedId
    // pre-define fields in the form
    //Ext.MessageBox.alert('提示',selectedId);
    var m = gridPanel.getSelections();
    if (m.length > 0 && m.length == 1) {
        var selectedId = m[0].get("id");
        var costlevel = new Ext.form.TextField({
            fieldLabel: '消费级别',
            allowBlank: false,
            name: 'cost_level',
            anchor: '90%'
        });
        var consumption = new Ext.form.TextField({
            fieldLabel: '消费金额',
            allowBlank: false,
            name: 'consumption',
            anchor: '90%'
        });
        var remark = new Ext.form.TextField({
            fieldLabel: '备注',
            allowBlank: false,
            name: 'remark',
            anchor: '90%'
        });
        // create form panel
        var editFormPanel = new Ext.form.FormPanel({
            baseCls: 'x-plain',
            labelWidth: 75,
            url: '/admin/editCostLevel?id=' + selectedId,
            reader: new Ext.data.JsonReader({
                root: 'root'
            }, ['id', 'cost_level', 'consumption', 'remark']),
            
            items: [costlevel, consumption, remark]
        });
        
        // load form and assign value to fields
        editFormPanel.form.load({
            url: '/admin/getCostLevelByID?id=' + selectedId,
            waitMsg: '正在载入数据...',
            success: function(form, action){
            //Ext.MessageBox.alert('提示信息', '信息加载成功！');
            },
            failure: function(form, action){
                Ext.MessageBox.alert('提示信息', '信息加载失败');
            }
        });
        
        // define window and show it in desktop
        var editCostLevelWindow = new Ext.Window({
            title: '编辑消费级别',
            width: 300,
            height: 150,
            minWidth: 300,
            minHeight: 150,
            layout: 'fit',
            plain: true,
            bodyStyle: 'padding:5px;',
            buttonAlign: 'center',
            items: editFormPanel,
            modal: true,
            buttons: [{
                text: '提交',
                handler: function(){
                    // check form value
                    if (editFormPanel.form.isValid()) {
                        editFormPanel.form.submit({
                            params: {
                                id: selectedId
                            },
                            waitMsg: '处理过程中...',
                            failure: function(form, action){
                                //debugger;
                                Ext.MessageBox.alert('错误提示', action.failureType);
                            },
                            success: function(form, action){
                                Ext.MessageBox.alert('确认', '提交成功');
                                editCostLevelWindow.hide();
                                dataStore.load();
                            }
                        });
                    }
                    else {
                        Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
                    }
                }
            }, {
                text: '取消',
                handler: function(){
                    editCostLevelWindow.hide();
                }
            }]
        });
        editCostLevelWindow.show();
    }
    else {
        Ext.MessageBox.alert('提示', "请先选择一条要编辑记录");
    }
}

//---------------------Create Department------------------------
function CreateDepartment(dataStore){

    // pre-define fields in the form
    var departmentname = new Ext.form.TextField({
        fieldLabel: '部门名称',
        allowBlank: false,
        name: 'name',
        anchor: '90%'
    });
    var area = new Ext.form.ComboBox({
        store: new Ext.data.Store({
            reader: new Ext.data.ArrayReader({}, ['value']),
            data: [['市南'], ['市北'], ['四方'], ['李村'], ['城阳'], ['黄岛'], ['崂山']]
        }),
        name: 'area',
        fieldLabel: '区域',
        resiable: true,
        typeAhead: true,
        width: 70,
        handleHeight: 100,
        displayField: 'value',
        valueField: 'value',
        nameField: 'status',
        selectOnFocus: true,
        mode: 'local',
        selectOnFocus: true,
        triggerAction: 'all', //这个属性非常重要,可以在选择一个值以后,依然还显示其它的值.
        readOnly: false,
        allowBlank: true
    });
    
    var formPanel = new Ext.form.FormPanel({
        baseCls: 'x-plain',
        labelWidth: 75,
        url: '/admin/addDepartment',
        defaultType: 'textfield',
        items: [departmentname, area]
    });
    
    // define window and show it in desktop
    var addDepartmentWindow = new Ext.Window({
        title: '增加部门',
        width: 300,
        height: 150,
        minWidth: 300,
        minHeight: 150,
        layout: 'fit',
        plain: true,
        bodyStyle: 'padding:5px;',
        buttonAlign: 'center',
        items: formPanel,
        modal: true,
        buttons: [{
            text: '增加',
            handler: function(){
                // check form value
                if (formPanel.form.isValid()) {
                    formPanel.form.submit({
                        waitMsg: 'In processing',
                        success: function(form, action){
                            Ext.MessageBox.alert('提示', '提交成功');
                            addDepartmentWindow.destroy();
                            dataStore.load();
                        },
                        failure: function(form, action){
                            Ext.MessageBox.alert('提交错误消息', '提交失败');
                        }
                    });
                }
                else {
                    Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
                }
            }
        }, {
            text: '取消',
            handler: function(){
                addDepartmentWindow.destroy();
            }
        }]
    });
    
    addDepartmentWindow.show();
};
//----------------Delete Department--------------------------
function DeleteDepartment(dataStore, gridPanel){
    // get the selected items
    var m = gridPanel.getSelections();
    if (m.length > 0) {
        Ext.MessageBox.confirm('提示', '你真的要删除这些部门吗？', function(btn){
            if (btn == 'yes') {
                var jsonData = "[";
                for (var i = 0, len = m.length; i < len; i++) {
                    var ss = "{\"id\":\"" + m[i].get("id") + "\"}";
                    if (i == 0)
                        jsonData = jsonData + ss;
                    else
                        jsonData = jsonData + "," + ss;
                    dataStore.remove(m[i]);
                }
                jsonData = jsonData + "]";
                //Ext.MessageBox.alert(jsonData);
                dataStore.load({
                    params: {
                        delData: jsonData
                    }
                });
            }
        });
    }
    else {
        Ext.MessageBox.alert('错误提示', '要删除部门时，请至少选择一个部门');
    }
};

//------------Edit Department-----------------
function EditDepartment(dataStore, gridPanel){//selectedId
    // pre-define fields in the form
    //Ext.MessageBox.alert('提示',selectedId);
    var m = gridPanel.getSelections();
    if (m.length > 0 && m.length == 1) {
        var selectedId = m[0].get("id");
        var departmentname = new Ext.form.TextField({
            fieldLabel: '部门管理',
            allowBlank: false,
            name: 'name',
            anchor: '90%'
        });
        var area = new Ext.form.ComboBox({
            store: new Ext.data.Store({
                reader: new Ext.data.ArrayReader({}, ['value']),
                data: [['市南'], ['市北'], ['四方'], ['李村'], ['城阳'], ['黄岛'], ['崂山']]
            }),
            name: 'area',
            fieldLabel: '区域',
            resiable: true,
            typeAhead: true,
            width: 70,
            handleHeight: 100,
            displayField: 'value',
            valueField: 'value',
            nameField: 'status',
            selectOnFocus: true,
            mode: 'local',
            selectOnFocus: true,
            triggerAction: 'all', //这个属性非常重要,可以在选择一个值以后,依然还显示其它的值.
            readOnly: false,
            allowBlank: true
        });
        
        // create form panel
        var editFormPanel = new Ext.form.FormPanel({
            baseCls: 'x-plain',
            labelWidth: 75,
            url: '/admin/editDepartment?id=' + selectedId,
            reader: new Ext.data.JsonReader({
                root: 'root'
            }, ['id', 'name', 'area']),
            items: [departmentname, area]
        });
        
        // load form and assign value to fields
        editFormPanel.form.load({
            url: '/admin/getDepartmentByID?id=' + selectedId,
            waitMsg: '正在载入数据...',
            success: function(form, action){
            //Ext.MessageBox.alert('提示信息', '信息加载成功！');
            },
            failure: function(form, action){
                Ext.MessageBox.alert('提示信息', '信息加载失败');
            }
        });
        
        // define window and show it in desktop
        var editDepartmentWindow = new Ext.Window({
            title: '编辑部门',
            width: 300,
            height: 150,
            minWidth: 300,
            minHeight: 150,
            layout: 'fit',
            plain: true,
            bodyStyle: 'padding:5px;',
            buttonAlign: 'center',
            items: editFormPanel,
            modal: true,
            buttons: [{
                text: '提交',
                handler: function(){
                    // check form value
                    if (editFormPanel.form.isValid()) {
                        editFormPanel.form.submit({
                            params: {
                                id: selectedId
                            },
                            waitMsg: '处理过程中...',
                            failure: function(form, action){
                                //debugger;
                                Ext.MessageBox.alert('错误提示', action.failureType);
                            },
                            success: function(form, action){
                                Ext.MessageBox.alert('确认', '提交成功');
                                editDepartmentWindow.hide();
                                dataStore.load();
                            }
                        });
                    }
                    else {
                        Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
                    }
                }
            }, {
                text: '取消',
                handler: function(){
                    editDepartmentWindow.hide();
                }
            }]
        });
        editDepartmentWindow.show();
    }
    else {
        Ext.MessageBox.alert('提示', "请先选择一条要编辑记录");
    }
}

//---------------------Create PaymentType------------------------
function CreatePaymentType(dataStore){

    // pre-define fields in the form
    var paymenttype = new Ext.form.TextField({
        fieldLabel: '支付方式',
        allowBlank: false,
        name: 'payment_type',
        anchor: '90%'
    });
    
    var formPanel = new Ext.form.FormPanel({
        baseCls: 'x-plain',
        labelWidth: 75,
        url: '/admin/addPaymentType',
        defaultType: 'textfield',
        items: [paymenttype]
    });
    
    // define window and show it in desktop
    var addPaymentTypeWindow = new Ext.Window({
        title: '增加支付方式',
        width: 300,
        height: 150,
        minWidth: 300,
        minHeight: 150,
        layout: 'fit',
        plain: true,
        bodyStyle: 'padding:5px;',
        buttonAlign: 'center',
        items: formPanel,
        modal: true,
        buttons: [{
            text: '增加',
            handler: function(){
                // check form value
                if (formPanel.form.isValid()) {
                    formPanel.form.submit({
                        waitMsg: 'In processing',
                        success: function(form, action){
                            Ext.MessageBox.alert('提示', '提交成功');
                            addPaymentTypeWindow.destroy();
                            dataStore.load();
                        },
                        failure: function(form, action){
                            Ext.MessageBox.alert('提交错误消息', '提交失败');
                        }
                    });
                }
                else {
                    Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
                }
            }
        }, {
            text: '取消',
            handler: function(){
                addPaymentTypeWindow.destroy();
            }
        }]
    });
    addPaymentTypeWindow.show();
};
//----------------Delete PaymentType--------------------------
function DeletePaymentType(dataStore, gridPanel){
    // get the selected items
    var m = gridPanel.getSelections();
    if (m.length > 0) {
        Ext.MessageBox.confirm('提示', '你真的要删除这些用户吗？', function(btn){
            if (btn == 'yes') {
                var jsonData = "[";
                for (var i = 0, len = m.length; i < len; i++) {
                    var ss = "{\"id\":\"" + m[i].get("id") + "\"}";
                    if (i == 0)
                        jsonData = jsonData + ss;
                    else
                        jsonData = jsonData + "," + ss;
                    dataStore.remove(m[i]);
                }
                jsonData = jsonData + "]";
                //Ext.MessageBox.alert(jsonData);
                dataStore.load({
                    params: {
                        delData: jsonData
                    }
                });
            }
        });
    }
    else {
        Ext.MessageBox.alert('错误提示', '要删除支付方式时，请至少选择一个支付方式');
    }
};

//------------Edit PaymentType-----------------
function EditPaymentType(dataStore, gridPanel){//selectedId
    // pre-define fields in the form
    //Ext.MessageBox.alert('提示',selectedId);
    var m = gridPanel.getSelections();
    if (m.length > 0 && m.length == 1) {
        var selectedId = m[0].get("id");
        var paymenttype = new Ext.form.TextField({
            fieldLabel: '支付方式',
            allowBlank: false,
            name: 'payment_type',
            anchor: '90%'
        });
        
        // create form panel
        var editFormPanel = new Ext.form.FormPanel({
            baseCls: 'x-plain',
            labelWidth: 75,
            url: '/admin/editPaymentType?id=' + selectedId,
            reader: new Ext.data.JsonReader({
                root: 'root'
            }, ['id', 'payment_type']),
            
            items: [paymenttype]
        });
        
        // load form and assign value to fields
        editFormPanel.form.load({
            url: '/admin/getPaymentTypeByID?id=' + selectedId,
            waitMsg: '正在载入数据...',
            success: function(form, action){
            //Ext.MessageBox.alert('提示信息', '信息加载成功！');
            },
            failure: function(form, action){
                Ext.MessageBox.alert('提示信息', '信息加载失败');
            }
        });
        
        // define window and show it in desktop
        var editPaymentTypeWindow = new Ext.Window({
            title: '编辑支付方式',
            width: 300,
            height: 150,
            minWidth: 300,
            minHeight: 150,
            layout: 'fit',
            plain: true,
            bodyStyle: 'padding:5px;',
            buttonAlign: 'center',
            items: editFormPanel,
            modal: true,
            buttons: [{
                text: '提交',
                handler: function(){
                    // check form value
                    if (editFormPanel.form.isValid()) {
                        editFormPanel.form.submit({
                            params: {
                                id: selectedId
                            },
                            waitMsg: '处理过程中...',
                            failure: function(form, action){
                                //debugger;
                                Ext.MessageBox.alert('错误提示', action.failureType);
                            },
                            success: function(form, action){
                                Ext.MessageBox.alert('确认', '提交成功');
                                editPaymentTypeWindow.hide();
                                dataStore.load();
                            }
                        });
                    }
                    else {
                        Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
                    }
                }
            }, {
                text: '取消',
                handler: function(){
                    editPaymentTypeWindow.hide();
                }
            }]
        });
        editPaymentTypeWindow.show();
    }
    else {
        Ext.MessageBox.alert('提示', "请先选择一条要编辑记录");
    }
}

//---------------------Create PlaneTax------------------------
function CreatePlaneTax(dataStore){

    // pre-define fields in the form
    var planetype = new Ext.form.TextField({
        fieldLabel: '飞机类型',
        allowBlank: false,
        name: 'plane_type',
        anchor: '90%'
    });
    
    var tax = new Ext.form.TextField({
        fieldLabel: '税费',
        allowBlank: false,
        name: 'tax',
        anchor: '90%'
    });
    
    var formPanel = new Ext.form.FormPanel({
        baseCls: 'x-plain',
        labelWidth: 75,
        url: '/admin/addPlaneTax',
        defaultType: 'textfield',
        items: [planetype, tax]
    });
    
    // define window and show it in desktop
    var addPlaneTaxWindow = new Ext.Window({
        title: '增加机税',
        width: 300,
        height: 150,
        minWidth: 300,
        minHeight: 150,
        layout: 'fit',
        plain: true,
        bodyStyle: 'padding:5px;',
        buttonAlign: 'center',
        items: formPanel,
        modal: true,
        buttons: [{
            text: '增加',
            handler: function(){
                // check form value
                if (formPanel.form.isValid()) {
                    formPanel.form.submit({
                        waitMsg: 'In processing',
                        success: function(form, action){
                            Ext.MessageBox.alert('提示', '提交成功');
                            addPlaneTaxWindow.destroy();
                            dataStore.load();
                        },
                        failure: function(form, action){
                            Ext.MessageBox.alert('提交错误消息', '提交失败');
                        }
                    });
                }
                else {
                    Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
                }
            }
        }, {
            text: '取消',
            handler: function(){
                addPlaneTaxWindow.destroy();
            }
        }]
    });
    
    addPlaneTaxWindow.show();
};
//----------------Delete PlaneTax--------------------------
function DeletePlaneTax(dataStore, gridPanel){
    // get the selected items
    var m = gridPanel.getSelections();
    if (m.length > 0) {
        Ext.MessageBox.confirm('提示', '你真的要删除这些用户吗？', function(btn){
            if (btn == 'yes') {
                var jsonData = "[";
                for (var i = 0, len = m.length; i < len; i++) {
                    var ss = "{\"id\":\"" + m[i].get("id") + "\"}";
                    if (i == 0)
                        jsonData = jsonData + ss;
                    else
                        jsonData = jsonData + "," + ss;
                    dataStore.remove(m[i]);
                }
                jsonData = jsonData + "]";
                //Ext.MessageBox.alert(jsonData);
                dataStore.load({
                    params: {
                        delData: jsonData
                    }
                });
            }
        });
    }
    else {
        Ext.MessageBox.alert('错误提示', '要删除机税时，请至少选择一个机税');
    }
};

//------------Edit PlaneTax-----------------
function EditPlaneTax(dataStore, gridPanel){//selectedId
    // pre-define fields in the form
    //Ext.MessageBox.alert('提示',selectedId);
    var m = gridPanel.getSelections();
    if (m.length > 0 && m.length == 1) {
        var selectedId = m[0].get("id");
        var planetype = new Ext.form.TextField({
            fieldLabel: '飞机类型',
            allowBlank: false,
            name: 'plane_type',
            anchor: '90%'
        });
        
        var tax = new Ext.form.TextField({
            fieldLabel: '税费',
            allowBlank: false,
            name: 'tax',
            anchor: '90%'
        });
        
        // create form panel
        var editFormPanel = new Ext.form.FormPanel({
            baseCls: 'x-plain',
            labelWidth: 75,
            url: '/admin/editPlaneTax?id=' + selectedId,
            reader: new Ext.data.JsonReader({
                root: 'root'
            }, ['id', 'plane_type', 'tax']),
            
            items: [planetype, tax]
        });
        
        // load form and assign value to fields
        editFormPanel.form.load({
            url: '/admin/getPlaneTaxByID?id=' + selectedId,
            waitMsg: '正在载入数据...',
            success: function(form, action){
            //Ext.MessageBox.alert('提示信息', '信息加载成功！');
            },
            failure: function(form, action){
                Ext.MessageBox.alert('提示信息', '信息加载失败');
            }
        });
        
        // define window and show it in desktop
        var editPlaneTaxWindow = new Ext.Window({
            title: '编辑机税',
            width: 300,
            height: 150,
            minWidth: 300,
            minHeight: 150,
            layout: 'fit',
            plain: true,
            bodyStyle: 'padding:5px;',
            buttonAlign: 'center',
            items: editFormPanel,
            modal: true,
            buttons: [{
                text: '提交',
                handler: function(){
                    // check form value
                    if (editFormPanel.form.isValid()) {
                        editFormPanel.form.submit({
                            params: {
                                id: selectedId
                            },
                            waitMsg: '处理过程中...',
                            failure: function(form, action){
                                //debugger;
                                Ext.MessageBox.alert('错误提示', action.failureType);
                            },
                            success: function(form, action){
                                Ext.MessageBox.alert('确认', '提交成功');
                                editPlaneTaxWindow.hide();
                                dataStore.load();
                            }
                        });
                    }
                    else {
                        Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
                    }
                }
            }, {
                text: '取消',
                handler: function(){
                    editPlaneTaxWindow.hide();
                }
            }]
        });
        editPlaneTaxWindow.show();
    }
    else {
        Ext.MessageBox.alert('提示', "请先选择一条要编辑记录");
    }
};

//---------------------Create Position------------------------
function CreatePosition(dataStore){

    // pre-define fields in the form
    //                    var airwaysname = new Ext.form.TextField({
    //                        fieldLabel: '航空公司',
    //                        allowBlank: false,
    //                        name: 'airways_name',
    //                        anchor: '90%'
    //                    });
    var airwaysname = new Ext.form.ComboBox({
        store: new Ext.data.Store({
            proxy: new Ext.data.HttpProxy({
                url: '/admin/getInternalAirways'
            }),
            reader: new Ext.data.JsonReader({
                root: 'root',
                id: 'id'
            }, ['id', 'airways_name'])
        }),
        name: 'customer_type',
        loadingText: '正在加载...',
        displayField: 'airways_name',
        valueField: 'id',
        mode: 'remote',
        triggerAction: 'all',
        hiddenName: 'airways_name_id',
        fieldLabel: '空港名称',
        emptyText: '请选择...',
        editable: false,
        allowBlank: false,
        width: 70,
        maxHeight: 150,
        tabIndex: 4
    });
    var positioncode = new Ext.form.TextField({
        fieldLabel: '仓位代码',
        allowBlank: false,
        name: 'position_code',
        anchor: '90%'
    });
    var discount = new Ext.form.TextField({
        fieldLabel: '折扣',
        allowBlank: false,
        name: 'discount',
        anchor: '90%'
    });
    var formPanel = new Ext.form.FormPanel({
        baseCls: 'x-plain',
        labelWidth: 75,
        url: '/admin/addPosition',
        defaultType: 'textfield',
        items: [airwaysname, positioncode, discount]
    });
    
    // define window and show it in desktop
    var addPositionWindow = new Ext.Window({
        title: '增加仓位',
        width: 300,
        height: 150,
        minWidth: 300,
        minHeight: 150,
        layout: 'fit',
        plain: true,
        bodyStyle: 'padding:5px;',
        buttonAlign: 'center',
        items: formPanel,
        modal: true,
        buttons: [{
            text: '增加',
            handler: function(){
                // check form value
                if (formPanel.form.isValid()) {
                    formPanel.form.submit({
                        waitMsg: 'In processing',
                        success: function(form, action){
                            Ext.MessageBox.alert('提示', '提交成功');
                            addPositionWindow.destroy();
                            dataStore.load();
                        },
                        failure: function(form, action){
                            Ext.MessageBox.alert('提交错误消息', '提交失败');
                        }
                    });
                }
                else {
                    Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
                }
            }
        }, {
            text: '取消',
            handler: function(){
                addPositionWindow.destroy();
            }
        }]
    });
    
    addPositionWindow.show();
};
//----------------Delete Position--------------------------
function DeletePosition(dataStore, gridPanel){
    // get the selected items
    var m = gridPanel.getSelectionModel();
    if (m != null) {
        Ext.MessageBox.confirm('提示', '你真的要删除这个仓位吗？', function(btn){
            if (btn == 'yes') {
                var jsonData = "[{id:\"" + m.selection.record.data.id + "\"}]";
                dataStore.load({
                    params: {
                        delData: jsonData
                    }
                });
            }
        });
    }
    else {
        Ext.MessageBox.alert('错误提示', '要删除仓位时，请至少选择一个仓位');
    }
};

//------------Edit Position-----------------
function EditPosition(dataStore, gridPanel){//selectedId
    // pre-define fields in the form
    //Ext.MessageBox.alert('提示',selectedId);
    var m = gridPanel.getSelections();
    if (m.length > 0 && m.length == 1) {
        var selectedId = m[0].get("id");
        var airportname = new Ext.form.TextField({
            fieldLabel: '仓位',
            allowBlank: false,
            name: 'airport_name',
            anchor: '90%'
        });
        var airportcode = new Ext.form.TextField({
            fieldLabel: '仓位',
            allowBlank: false,
            name: 'airport_code',
            anchor: '90%'
        });
        // create form panel
        var editFormPanel = new Ext.form.FormPanel({
            baseCls: 'x-plain',
            labelWidth: 75,
            url: '/admin/editPosition?id=' + selectedId,
            reader: new Ext.data.JsonReader({
                root: 'root'
            }, ['id', 'airport_name', 'airport_code']),
            
            items: [airportname, airportcode]
        });
        
        // load form and assign value to fields
        editFormPanel.form.load({
            url: '/admin/getPositionByID?id=' + selectedId,
            waitMsg: '正在载入数据...',
            success: function(form, action){
            //Ext.MessageBox.alert('提示信息', '信息加载成功！');
            },
            failure: function(form, action){
                Ext.MessageBox.alert('提示信息', '信息加载失败');
            }
        });
        
        // define window and show it in desktop
        var editPositionWindow = new Ext.Window({
            title: '编辑仓位',
            width: 300,
            height: 150,
            minWidth: 300,
            minHeight: 150,
            layout: 'fit',
            plain: true,
            bodyStyle: 'padding:5px;',
            buttonAlign: 'center',
            items: editFormPanel,
            modal: true,
            buttons: [{
                text: '提交',
                handler: function(){
                    if (editFormPanel.form.isValid()) {
                        editFormPanel.form.submit({
                            params: {
                                id: selectedId
                            },
                            waitMsg: '处理过程中...',
                            failure: function(form, action){
                                Ext.MessageBox.alert('错误提示', action.failureType);
                            },
                            success: function(form, action){
                                Ext.MessageBox.alert('确认', '提交成功');
                                editPositionWindow.hide();
                                dataStore.load();
                            }
                        });
                    }
                    else {
                        Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
                    }
                }
            }, {
                text: '取消',
                handler: function(){
                    editPositionWindow.hide();
                }
            }]
        });
        editPositionWindow.show();
    }
    else {
        Ext.MessageBox.alert('提示', "请先选择一条要编辑记录");
    }
};
//------------Edit Position-----------------
function SavePosition(dataStore, gridPanel){//selectedId
    var m = dataStore.modified.slice(0);
    var jsonData = "[";
    for (var i = 0, len = m.length; i < len; i++) {
        //alert(m[i].data["user_name"]);
        var ss = Ext.util.JSON.encode(m[i].data);
        //alert(ss);
        if (i == 0)
            jsonData = jsonData + ss;
        else
            jsonData = jsonData + "," + ss;
    }
    jsonData = jsonData + "]";
    if (jsonData != "[]") {
        Ext.Ajax.request({
            url: '/admin/savePositions',
            params: {
                json: jsonData
            },
            waitMsg: '正在处理，请稍候...',
            method: 'POST',
            success: function(result, request){
                //Ext.MessageBox.alert("提示!", "保存仓位成功！");
                dataStore.load();
            },
            failure: function(result, request){
                Ext.MessageBox.alert("提示!", "保存仓位失败！");
            }
        });
    }
}
//日期加天.yyyy-mm-dd,返回为yyyy-mm-dd
function dateAddStepDay(oriDate,days){
    return Ext.util.Format.dateRenderer('Y-m-d')(new Date(Ext.util.Format.dateRenderer('m/d/Y')(oriDate)).add(Date.DAY, days));
}
//根据yyyy-mm-dd格式日期获取之前或者之后几天的日期格式,返回格式也为yyyy-mm-dd
function getDateByNum(oriDateStr,num){
    var yyyy = oriDateStr.substring(0,oriDateStr.indexOf("-"));
    var mth = oriDateStr.substring(oriDateStr.indexOf("-")+1,oriDateStr.lastIndexOf("-"));
    if (mth.indexOf("0")==0){
        mth = (parseInt(mth.substring(1))-1)+"";
    }else{
        mth = (parseInt(mth)-1)+"";
    }
    var dd = oriDateStr.substring(oriDateStr.lastIndexOf("-")+1);
    var day = new Date(yyyy,mth,dd);
    var new_date = Ext.util.Format.dateRenderer('Y-m-d')(day.add(Date.DAY, num));
    return new_date;
}

function isNumber(str){    
    if(""==str){
        return false;
    }
    var reg = /\D/;
    return str.match(reg)==null;
} 

function isSFZ(str){   
    if(str.length!=15&&str.length!=18){//身份证长度不正确
        return false;
    }
    if(str.length==15){
        if(!isNumber(str)){
            return false;
        }
    }else{
        var str1 = str.substring(0,17);
        var str2 = str.substring(17,18);
        var alpha = "X0123456789";
        if(!isNumber(str1)||alpha.indexOf(str2)==-1){
            return false;
        }
    }
    return true;
} 


